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
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 237, 310 ] }
9,000
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 534, 616 ] }
9,001
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 895, 983 ] }
9,002
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 1647, 1726 ] }
9,003
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 2039, 2141 ] }
9,004
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
add
function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; }
/** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 259, 445 ] }
9,005
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
sub
function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); }
/** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 723, 864 ] }
9,006
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
sub
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; }
/** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 1162, 1359 ] }
9,007
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
mul
function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; }
/** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 1613, 2089 ] }
9,008
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
div
function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); }
/** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 2560, 2697 ] }
9,009
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
div
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; }
/** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 3188, 3471 ] }
9,010
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
mod
function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 3931, 4066 ] }
9,011
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
mod
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 4546, 4717 ] }
9,012
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
isContract
function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); }
/** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 606, 1230 ] }
9,013
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
sendValue
function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); }
/** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 2160, 2562 ] }
9,014
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
functionCall
function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); }
/** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 3318, 3496 ] }
9,015
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
functionCall
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); }
/** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 3721, 3922 ] }
9,016
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
functionCallWithValue
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); }
/** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 4292, 4523 ] }
9,017
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
functionCallWithValue
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); }
/** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 4774, 5095 ] }
9,018
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
Ownable
contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
owner
function owner() public view returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 497, 581 ] }
9,019
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
Ownable
contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
renounceOwnership
function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); }
/** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 1139, 1292 ] }
9,020
NipponInu
NipponInu.sol
0xc4ae41030535080907e5fbf1ad8f11fcbbc86199
Solidity
Ownable
contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
transferOwnership
function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://8911bc60efd34d07cefe7032fb8eb60586a10ae7ab658ba04757b83418508612
{ "func_code_index": [ 1442, 1691 ] }
9,021
PB0
contracts/ERC20.sol
0x29c188b27b6b2134385f1eda2d1d8eff5446e0cf
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; address public _minter; mapping (address => uint256) private _balances; uint256 private _totalSupply; /** * @dev Total number of tokens in existence. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev Gets the balance of the specified address. * @param owner The address to query the balance of. * @return A uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Transfer token to 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) { _transfer(msg.sender, to, value); return true; } /** * @dev Transfer token for a specified addresses. * @param from The address to transfer from. * @param to The address to transfer to. * @param value The amount to be transferred. */ function _transfer(address from, address to, uint256 value) internal { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(value <= _balances[from], "Insufficient balance."); _balances[from] = _balances[from].sub(value); _balances[to] = _balances[to].add(value); emit Transfer(from, to, value); } /** * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the * proper events are emitted. * @param account The account that will receive the created tokens. * @param value The amount that will be created. */ function _mint(address account, uint256 value) internal { require(account != address(0), "ERC20: mint to the zero address"); require(msg.sender == _minter); require(value < 1e60); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://eips.ethereum.org/EIPS/eip-20 * Originally based on code by FirstBlood: * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol * * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for * all accounts just by listening to said events. Note that this isn't required by the specification, and other * compliant implementations may not do it. */
NatSpecMultiLine
totalSupply
function totalSupply() public view returns (uint256) { return _totalSupply; }
/** * @dev Total number of tokens in existence. */
NatSpecMultiLine
v0.5.8+commit.23d335f2
bzzr://430ba050069fa850d6904fe3f31c87a594a8868dd674214e333e01501c33488e
{ "func_code_index": [ 254, 350 ] }
9,022
PB0
contracts/ERC20.sol
0x29c188b27b6b2134385f1eda2d1d8eff5446e0cf
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; address public _minter; mapping (address => uint256) private _balances; uint256 private _totalSupply; /** * @dev Total number of tokens in existence. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev Gets the balance of the specified address. * @param owner The address to query the balance of. * @return A uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Transfer token to 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) { _transfer(msg.sender, to, value); return true; } /** * @dev Transfer token for a specified addresses. * @param from The address to transfer from. * @param to The address to transfer to. * @param value The amount to be transferred. */ function _transfer(address from, address to, uint256 value) internal { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(value <= _balances[from], "Insufficient balance."); _balances[from] = _balances[from].sub(value); _balances[to] = _balances[to].add(value); emit Transfer(from, to, value); } /** * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the * proper events are emitted. * @param account The account that will receive the created tokens. * @param value The amount that will be created. */ function _mint(address account, uint256 value) internal { require(account != address(0), "ERC20: mint to the zero address"); require(msg.sender == _minter); require(value < 1e60); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://eips.ethereum.org/EIPS/eip-20 * Originally based on code by FirstBlood: * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol * * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for * all accounts just by listening to said events. Note that this isn't required by the specification, and other * compliant implementations may not do it. */
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 balance of. * @return A uint256 representing the amount owned by the passed address. */
NatSpecMultiLine
v0.5.8+commit.23d335f2
bzzr://430ba050069fa850d6904fe3f31c87a594a8868dd674214e333e01501c33488e
{ "func_code_index": [ 564, 675 ] }
9,023
PB0
contracts/ERC20.sol
0x29c188b27b6b2134385f1eda2d1d8eff5446e0cf
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; address public _minter; mapping (address => uint256) private _balances; uint256 private _totalSupply; /** * @dev Total number of tokens in existence. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev Gets the balance of the specified address. * @param owner The address to query the balance of. * @return A uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Transfer token to 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) { _transfer(msg.sender, to, value); return true; } /** * @dev Transfer token for a specified addresses. * @param from The address to transfer from. * @param to The address to transfer to. * @param value The amount to be transferred. */ function _transfer(address from, address to, uint256 value) internal { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(value <= _balances[from], "Insufficient balance."); _balances[from] = _balances[from].sub(value); _balances[to] = _balances[to].add(value); emit Transfer(from, to, value); } /** * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the * proper events are emitted. * @param account The account that will receive the created tokens. * @param value The amount that will be created. */ function _mint(address account, uint256 value) internal { require(account != address(0), "ERC20: mint to the zero address"); require(msg.sender == _minter); require(value < 1e60); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://eips.ethereum.org/EIPS/eip-20 * Originally based on code by FirstBlood: * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol * * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for * all accounts just by listening to said events. Note that this isn't required by the specification, and other * compliant implementations may not do it. */
NatSpecMultiLine
transfer
function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; }
/** * @dev Transfer token to a specified address. * @param to The address to transfer to. * @param value The amount to be transferred. */
NatSpecMultiLine
v0.5.8+commit.23d335f2
bzzr://430ba050069fa850d6904fe3f31c87a594a8868dd674214e333e01501c33488e
{ "func_code_index": [ 845, 990 ] }
9,024
PB0
contracts/ERC20.sol
0x29c188b27b6b2134385f1eda2d1d8eff5446e0cf
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; address public _minter; mapping (address => uint256) private _balances; uint256 private _totalSupply; /** * @dev Total number of tokens in existence. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev Gets the balance of the specified address. * @param owner The address to query the balance of. * @return A uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Transfer token to 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) { _transfer(msg.sender, to, value); return true; } /** * @dev Transfer token for a specified addresses. * @param from The address to transfer from. * @param to The address to transfer to. * @param value The amount to be transferred. */ function _transfer(address from, address to, uint256 value) internal { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(value <= _balances[from], "Insufficient balance."); _balances[from] = _balances[from].sub(value); _balances[to] = _balances[to].add(value); emit Transfer(from, to, value); } /** * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the * proper events are emitted. * @param account The account that will receive the created tokens. * @param value The amount that will be created. */ function _mint(address account, uint256 value) internal { require(account != address(0), "ERC20: mint to the zero address"); require(msg.sender == _minter); require(value < 1e60); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://eips.ethereum.org/EIPS/eip-20 * Originally based on code by FirstBlood: * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol * * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for * all accounts just by listening to said events. Note that this isn't required by the specification, and other * compliant implementations may not do it. */
NatSpecMultiLine
_transfer
function _transfer(address from, address to, uint256 value) internal { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(value <= _balances[from], "Insufficient balance."); _balances[from] = _balances[from].sub(value); _balances[to] = _balances[to].add(value); emit Transfer(from, to, value); }
/** * @dev Transfer token for a specified addresses. * @param from The address to transfer from. * @param to The address to transfer to. * @param value The amount to be transferred. */
NatSpecMultiLine
v0.5.8+commit.23d335f2
bzzr://430ba050069fa850d6904fe3f31c87a594a8868dd674214e333e01501c33488e
{ "func_code_index": [ 1213, 1667 ] }
9,025
PB0
contracts/ERC20.sol
0x29c188b27b6b2134385f1eda2d1d8eff5446e0cf
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; address public _minter; mapping (address => uint256) private _balances; uint256 private _totalSupply; /** * @dev Total number of tokens in existence. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev Gets the balance of the specified address. * @param owner The address to query the balance of. * @return A uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Transfer token to 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) { _transfer(msg.sender, to, value); return true; } /** * @dev Transfer token for a specified addresses. * @param from The address to transfer from. * @param to The address to transfer to. * @param value The amount to be transferred. */ function _transfer(address from, address to, uint256 value) internal { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(value <= _balances[from], "Insufficient balance."); _balances[from] = _balances[from].sub(value); _balances[to] = _balances[to].add(value); emit Transfer(from, to, value); } /** * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the * proper events are emitted. * @param account The account that will receive the created tokens. * @param value The amount that will be created. */ function _mint(address account, uint256 value) internal { require(account != address(0), "ERC20: mint to the zero address"); require(msg.sender == _minter); require(value < 1e60); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://eips.ethereum.org/EIPS/eip-20 * Originally based on code by FirstBlood: * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol * * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for * all accounts just by listening to said events. Note that this isn't required by the specification, and other * compliant implementations may not do it. */
NatSpecMultiLine
_mint
function _mint(address account, uint256 value) internal { require(account != address(0), "ERC20: mint to the zero address"); require(msg.sender == _minter); require(value < 1e60); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); }
/** * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the * proper events are emitted. * @param account The account that will receive the created tokens. * @param value The amount that will be created. */
NatSpecMultiLine
v0.5.8+commit.23d335f2
bzzr://430ba050069fa850d6904fe3f31c87a594a8868dd674214e333e01501c33488e
{ "func_code_index": [ 2014, 2396 ] }
9,026
bannermfers
bannermfers.sol
0x5d5c31b173db1bfcb314a54f03519bbb11a2544b
Solidity
bannermfers
contract bannermfers is ERC721, Ownable { address public MFERS_ADDRESS; address payable public payments; IERC721 private _mfersContract; uint private _totalSupply; string private _metadataBaseURI; string private _metadataExtension; uint public cost = 0.0169 ether; /* events */ event Received(address, uint); /* metadata */ constructor(address mfersAddress, address _payments) ERC721("banner mfers", "bannermfer") Ownable() { setMfersAddress(mfersAddress); setMetadataBaseURI("https://gateway.pinata.cloud/ipfs/QmQoBpkMvrpuegnUvmp6jGg1xschRnvyMAi4YjMKrw9fn4/"); setMetadataExtenstion(".json"); payments = payable(_payments); } receive() external payable { emit Received(msg.sender, msg.value); } /* owner's functions */ function setMfersAddress(address newAddress) public onlyOwner { MFERS_ADDRESS = newAddress; _mfersContract = IERC721(MFERS_ADDRESS); } function setMetadataBaseURI(string memory uri) public onlyOwner { _metadataBaseURI = uri; } function setMetadataExtenstion(string memory extension) public onlyOwner { _metadataExtension = extension; } function withdraw() public onlyOwner { (bool sent,) = payable(payments).call{value: address(this).balance}(""); require(sent, "Failed to send Ether"); } /* Public functions */ function _mint(uint256 token) private { require(msg.value >= cost, "Price is 0.0169 Eth"); require(_mfersContract.ownerOf(token) == msg.sender, "You need to own the mfer"); _safeMint(msg.sender, token); _totalSupply += 1; } function mint(uint256 token) payable public { emit Received(msg.sender, msg.value); _mint(token); } function massMint(uint256[] memory tokens) payable public { require(msg.value >= (cost * tokens.length), "Price is 0.0169 Eth per banner"); for (uint i = 0; i < tokens.length; ++i) { require(_mfersContract.ownerOf(tokens[i]) == msg.sender, "You need to own the mfer"); _mint(tokens[i]); } } function totalSupply() public view returns(uint supply) { supply = _totalSupply; } function tokenURI(uint256 token) public view override(ERC721) returns(string memory) { return string(abi.encodePacked(_metadataBaseURI, Strings.toString(token), _metadataExtension)); } }
setMfersAddress
function setMfersAddress(address newAddress) public onlyOwner { MFERS_ADDRESS = newAddress; _mfersContract = IERC721(MFERS_ADDRESS); }
/* owner's functions */
Comment
v0.8.7+commit.e28d00a7
MIT
ipfs://742b42ad2671b5cf48cb3485f1a50ee4acb90a206e24522b73833494d3139696
{ "func_code_index": [ 862, 1024 ] }
9,027
bannermfers
bannermfers.sol
0x5d5c31b173db1bfcb314a54f03519bbb11a2544b
Solidity
bannermfers
contract bannermfers is ERC721, Ownable { address public MFERS_ADDRESS; address payable public payments; IERC721 private _mfersContract; uint private _totalSupply; string private _metadataBaseURI; string private _metadataExtension; uint public cost = 0.0169 ether; /* events */ event Received(address, uint); /* metadata */ constructor(address mfersAddress, address _payments) ERC721("banner mfers", "bannermfer") Ownable() { setMfersAddress(mfersAddress); setMetadataBaseURI("https://gateway.pinata.cloud/ipfs/QmQoBpkMvrpuegnUvmp6jGg1xschRnvyMAi4YjMKrw9fn4/"); setMetadataExtenstion(".json"); payments = payable(_payments); } receive() external payable { emit Received(msg.sender, msg.value); } /* owner's functions */ function setMfersAddress(address newAddress) public onlyOwner { MFERS_ADDRESS = newAddress; _mfersContract = IERC721(MFERS_ADDRESS); } function setMetadataBaseURI(string memory uri) public onlyOwner { _metadataBaseURI = uri; } function setMetadataExtenstion(string memory extension) public onlyOwner { _metadataExtension = extension; } function withdraw() public onlyOwner { (bool sent,) = payable(payments).call{value: address(this).balance}(""); require(sent, "Failed to send Ether"); } /* Public functions */ function _mint(uint256 token) private { require(msg.value >= cost, "Price is 0.0169 Eth"); require(_mfersContract.ownerOf(token) == msg.sender, "You need to own the mfer"); _safeMint(msg.sender, token); _totalSupply += 1; } function mint(uint256 token) payable public { emit Received(msg.sender, msg.value); _mint(token); } function massMint(uint256[] memory tokens) payable public { require(msg.value >= (cost * tokens.length), "Price is 0.0169 Eth per banner"); for (uint i = 0; i < tokens.length; ++i) { require(_mfersContract.ownerOf(tokens[i]) == msg.sender, "You need to own the mfer"); _mint(tokens[i]); } } function totalSupply() public view returns(uint supply) { supply = _totalSupply; } function tokenURI(uint256 token) public view override(ERC721) returns(string memory) { return string(abi.encodePacked(_metadataBaseURI, Strings.toString(token), _metadataExtension)); } }
_mint
function _mint(uint256 token) private { require(msg.value >= cost, "Price is 0.0169 Eth"); require(_mfersContract.ownerOf(token) == msg.sender, "You need to own the mfer"); _safeMint(msg.sender, token); _totalSupply += 1; }
/* Public functions */
Comment
v0.8.7+commit.e28d00a7
MIT
ipfs://742b42ad2671b5cf48cb3485f1a50ee4acb90a206e24522b73833494d3139696
{ "func_code_index": [ 1483, 1756 ] }
9,028
Resonance
TeamRewards.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
TeamRewards
contract TeamRewards { // -------------------- mapping ------------------------ // mapping(address => UserSystemInfo) public userSystemInfo;// user system information mapping mapping(address => address[]) public whitelistAddress; // Whitelist addresses defined at the beginning of the project // -------------------- array ------------------------ // address[5] internal admin = [address(0x8434750c01D702c9cfabb3b7C5AA2774Ee67C90D), address(0xD8e79f0D2592311E740Ff097FFb0a7eaa8cb506a), address(0x740beb9fa9CCC6e971f90c25C5D5CC77063a722D), address(0x1b5bbac599f1313dB3E8061A0A65608f62897B0C), address(0x6Fd6dF175B97d2E6D651b536761e0d36b33A9495)]; // -------------------- variate ------------------------ // address public resonanceAddress; address public owner; bool public whitelistTime; // -------------------- event ------------------------ // event TobeWhitelistAddress(address indexed user, address adminAddress); // -------------------- structure ------------------------ // // user system information struct UserSystemInfo { address userAddress; // user address address straightAddress; // straight Address address whiteAddress; // whiteList Address address adminAddress; // admin Address bool whitelist; // if whitelist } constructor() public{ whitelistTime = true; owner = msg.sender; } // -------------------- modifier ------------------------ // modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyAdmin () { address adminAddress = msg.sender; require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier mustAdmin (address adminAddress){ require(adminAddress != address(0)); require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier onlyResonance (){ require(msg.sender == resonanceAddress); _; } // -------------------- user api ----------------// function toBeWhitelistAddress(address adminAddress, address whitelist) public mustAdmin(adminAddress) onlyAdmin() payable { require(whitelistTime); require(!userSystemInfo[whitelist].whitelist); whitelistAddress[adminAddress].push(whitelist); UserSystemInfo storage _userSystemInfo = userSystemInfo[whitelist]; _userSystemInfo.straightAddress = adminAddress; _userSystemInfo.whiteAddress = whitelist; _userSystemInfo.adminAddress = adminAddress; _userSystemInfo.whitelist = true; emit TobeWhitelistAddress(whitelist, adminAddress); } // -------------------- Resonance api ----------------// function referralPeople(address userAddress,address referralAddress) public onlyResonance() { UserSystemInfo storage _userSystemInfo = userSystemInfo[userAddress]; _userSystemInfo.straightAddress = referralAddress; _userSystemInfo.whiteAddress = userSystemInfo[referralAddress].whiteAddress; _userSystemInfo.adminAddress = userSystemInfo[referralAddress].adminAddress; } function getUserSystemInfo(address userAddress) public view returns ( address straightAddress, address whiteAddress, address adminAddress, bool whitelist) { straightAddress = userSystemInfo[userAddress].straightAddress; whiteAddress = userSystemInfo[userAddress].whiteAddress; adminAddress = userSystemInfo[userAddress].adminAddress; whitelist = userSystemInfo[userAddress].whitelist; } function getUserreferralAddress(address userAddress) public view onlyResonance() returns (address ) { return userSystemInfo[userAddress].straightAddress; } // -------------------- Owner api ----------------// function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; } // -------------------- Admin api ---------------- // // set whitelist close function setWhitelistTime(bool off) public onlyAdmin() { whitelistTime = off; } function getWhitelistTime() public view returns (bool) { return whitelistTime; } // get all whitelist by admin address function getAdminWhitelistAddress(address adminx) public view returns (address[] memory) { return whitelistAddress[adminx]; } // check if the user is whitelist function isWhitelistAddress(address user) public view returns (bool) { return userSystemInfo[user].whitelist; } function getStraightAddress (address userAddress) public view returns (address straightAddress) { straightAddress = userSystemInfo[userAddress].straightAddress; } }
toBeWhitelistAddress
function toBeWhitelistAddress(address adminAddress, address whitelist) public mustAdmin(adminAddress) onlyAdmin() payable { require(whitelistTime); require(!userSystemInfo[whitelist].whitelist); whitelistAddress[adminAddress].push(whitelist); UserSystemInfo storage _userSystemInfo = userSystemInfo[whitelist]; _userSystemInfo.straightAddress = adminAddress; _userSystemInfo.whiteAddress = whitelist; _userSystemInfo.adminAddress = adminAddress; _userSystemInfo.whitelist = true; emit TobeWhitelistAddress(whitelist, adminAddress); }
// -------------------- user api ----------------//
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 2318, 2967 ] }
9,029
Resonance
TeamRewards.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
TeamRewards
contract TeamRewards { // -------------------- mapping ------------------------ // mapping(address => UserSystemInfo) public userSystemInfo;// user system information mapping mapping(address => address[]) public whitelistAddress; // Whitelist addresses defined at the beginning of the project // -------------------- array ------------------------ // address[5] internal admin = [address(0x8434750c01D702c9cfabb3b7C5AA2774Ee67C90D), address(0xD8e79f0D2592311E740Ff097FFb0a7eaa8cb506a), address(0x740beb9fa9CCC6e971f90c25C5D5CC77063a722D), address(0x1b5bbac599f1313dB3E8061A0A65608f62897B0C), address(0x6Fd6dF175B97d2E6D651b536761e0d36b33A9495)]; // -------------------- variate ------------------------ // address public resonanceAddress; address public owner; bool public whitelistTime; // -------------------- event ------------------------ // event TobeWhitelistAddress(address indexed user, address adminAddress); // -------------------- structure ------------------------ // // user system information struct UserSystemInfo { address userAddress; // user address address straightAddress; // straight Address address whiteAddress; // whiteList Address address adminAddress; // admin Address bool whitelist; // if whitelist } constructor() public{ whitelistTime = true; owner = msg.sender; } // -------------------- modifier ------------------------ // modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyAdmin () { address adminAddress = msg.sender; require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier mustAdmin (address adminAddress){ require(adminAddress != address(0)); require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier onlyResonance (){ require(msg.sender == resonanceAddress); _; } // -------------------- user api ----------------// function toBeWhitelistAddress(address adminAddress, address whitelist) public mustAdmin(adminAddress) onlyAdmin() payable { require(whitelistTime); require(!userSystemInfo[whitelist].whitelist); whitelistAddress[adminAddress].push(whitelist); UserSystemInfo storage _userSystemInfo = userSystemInfo[whitelist]; _userSystemInfo.straightAddress = adminAddress; _userSystemInfo.whiteAddress = whitelist; _userSystemInfo.adminAddress = adminAddress; _userSystemInfo.whitelist = true; emit TobeWhitelistAddress(whitelist, adminAddress); } // -------------------- Resonance api ----------------// function referralPeople(address userAddress,address referralAddress) public onlyResonance() { UserSystemInfo storage _userSystemInfo = userSystemInfo[userAddress]; _userSystemInfo.straightAddress = referralAddress; _userSystemInfo.whiteAddress = userSystemInfo[referralAddress].whiteAddress; _userSystemInfo.adminAddress = userSystemInfo[referralAddress].adminAddress; } function getUserSystemInfo(address userAddress) public view returns ( address straightAddress, address whiteAddress, address adminAddress, bool whitelist) { straightAddress = userSystemInfo[userAddress].straightAddress; whiteAddress = userSystemInfo[userAddress].whiteAddress; adminAddress = userSystemInfo[userAddress].adminAddress; whitelist = userSystemInfo[userAddress].whitelist; } function getUserreferralAddress(address userAddress) public view onlyResonance() returns (address ) { return userSystemInfo[userAddress].straightAddress; } // -------------------- Owner api ----------------// function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; } // -------------------- Admin api ---------------- // // set whitelist close function setWhitelistTime(bool off) public onlyAdmin() { whitelistTime = off; } function getWhitelistTime() public view returns (bool) { return whitelistTime; } // get all whitelist by admin address function getAdminWhitelistAddress(address adminx) public view returns (address[] memory) { return whitelistAddress[adminx]; } // check if the user is whitelist function isWhitelistAddress(address user) public view returns (bool) { return userSystemInfo[user].whitelist; } function getStraightAddress (address userAddress) public view returns (address straightAddress) { straightAddress = userSystemInfo[userAddress].straightAddress; } }
referralPeople
function referralPeople(address userAddress,address referralAddress) public onlyResonance() { UserSystemInfo storage _userSystemInfo = userSystemInfo[userAddress]; _userSystemInfo.straightAddress = referralAddress; _userSystemInfo.whiteAddress = userSystemInfo[referralAddress].whiteAddress; _userSystemInfo.adminAddress = userSystemInfo[referralAddress].adminAddress; }
// -------------------- Resonance api ----------------//
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 3032, 3463 ] }
9,030
Resonance
TeamRewards.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
TeamRewards
contract TeamRewards { // -------------------- mapping ------------------------ // mapping(address => UserSystemInfo) public userSystemInfo;// user system information mapping mapping(address => address[]) public whitelistAddress; // Whitelist addresses defined at the beginning of the project // -------------------- array ------------------------ // address[5] internal admin = [address(0x8434750c01D702c9cfabb3b7C5AA2774Ee67C90D), address(0xD8e79f0D2592311E740Ff097FFb0a7eaa8cb506a), address(0x740beb9fa9CCC6e971f90c25C5D5CC77063a722D), address(0x1b5bbac599f1313dB3E8061A0A65608f62897B0C), address(0x6Fd6dF175B97d2E6D651b536761e0d36b33A9495)]; // -------------------- variate ------------------------ // address public resonanceAddress; address public owner; bool public whitelistTime; // -------------------- event ------------------------ // event TobeWhitelistAddress(address indexed user, address adminAddress); // -------------------- structure ------------------------ // // user system information struct UserSystemInfo { address userAddress; // user address address straightAddress; // straight Address address whiteAddress; // whiteList Address address adminAddress; // admin Address bool whitelist; // if whitelist } constructor() public{ whitelistTime = true; owner = msg.sender; } // -------------------- modifier ------------------------ // modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyAdmin () { address adminAddress = msg.sender; require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier mustAdmin (address adminAddress){ require(adminAddress != address(0)); require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier onlyResonance (){ require(msg.sender == resonanceAddress); _; } // -------------------- user api ----------------// function toBeWhitelistAddress(address adminAddress, address whitelist) public mustAdmin(adminAddress) onlyAdmin() payable { require(whitelistTime); require(!userSystemInfo[whitelist].whitelist); whitelistAddress[adminAddress].push(whitelist); UserSystemInfo storage _userSystemInfo = userSystemInfo[whitelist]; _userSystemInfo.straightAddress = adminAddress; _userSystemInfo.whiteAddress = whitelist; _userSystemInfo.adminAddress = adminAddress; _userSystemInfo.whitelist = true; emit TobeWhitelistAddress(whitelist, adminAddress); } // -------------------- Resonance api ----------------// function referralPeople(address userAddress,address referralAddress) public onlyResonance() { UserSystemInfo storage _userSystemInfo = userSystemInfo[userAddress]; _userSystemInfo.straightAddress = referralAddress; _userSystemInfo.whiteAddress = userSystemInfo[referralAddress].whiteAddress; _userSystemInfo.adminAddress = userSystemInfo[referralAddress].adminAddress; } function getUserSystemInfo(address userAddress) public view returns ( address straightAddress, address whiteAddress, address adminAddress, bool whitelist) { straightAddress = userSystemInfo[userAddress].straightAddress; whiteAddress = userSystemInfo[userAddress].whiteAddress; adminAddress = userSystemInfo[userAddress].adminAddress; whitelist = userSystemInfo[userAddress].whitelist; } function getUserreferralAddress(address userAddress) public view onlyResonance() returns (address ) { return userSystemInfo[userAddress].straightAddress; } // -------------------- Owner api ----------------// function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; } // -------------------- Admin api ---------------- // // set whitelist close function setWhitelistTime(bool off) public onlyAdmin() { whitelistTime = off; } function getWhitelistTime() public view returns (bool) { return whitelistTime; } // get all whitelist by admin address function getAdminWhitelistAddress(address adminx) public view returns (address[] memory) { return whitelistAddress[adminx]; } // check if the user is whitelist function isWhitelistAddress(address user) public view returns (bool) { return userSystemInfo[user].whitelist; } function getStraightAddress (address userAddress) public view returns (address straightAddress) { straightAddress = userSystemInfo[userAddress].straightAddress; } }
allowResonance
function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; }
// -------------------- Owner api ----------------//
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 4221, 4327 ] }
9,031
Resonance
TeamRewards.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
TeamRewards
contract TeamRewards { // -------------------- mapping ------------------------ // mapping(address => UserSystemInfo) public userSystemInfo;// user system information mapping mapping(address => address[]) public whitelistAddress; // Whitelist addresses defined at the beginning of the project // -------------------- array ------------------------ // address[5] internal admin = [address(0x8434750c01D702c9cfabb3b7C5AA2774Ee67C90D), address(0xD8e79f0D2592311E740Ff097FFb0a7eaa8cb506a), address(0x740beb9fa9CCC6e971f90c25C5D5CC77063a722D), address(0x1b5bbac599f1313dB3E8061A0A65608f62897B0C), address(0x6Fd6dF175B97d2E6D651b536761e0d36b33A9495)]; // -------------------- variate ------------------------ // address public resonanceAddress; address public owner; bool public whitelistTime; // -------------------- event ------------------------ // event TobeWhitelistAddress(address indexed user, address adminAddress); // -------------------- structure ------------------------ // // user system information struct UserSystemInfo { address userAddress; // user address address straightAddress; // straight Address address whiteAddress; // whiteList Address address adminAddress; // admin Address bool whitelist; // if whitelist } constructor() public{ whitelistTime = true; owner = msg.sender; } // -------------------- modifier ------------------------ // modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyAdmin () { address adminAddress = msg.sender; require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier mustAdmin (address adminAddress){ require(adminAddress != address(0)); require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier onlyResonance (){ require(msg.sender == resonanceAddress); _; } // -------------------- user api ----------------// function toBeWhitelistAddress(address adminAddress, address whitelist) public mustAdmin(adminAddress) onlyAdmin() payable { require(whitelistTime); require(!userSystemInfo[whitelist].whitelist); whitelistAddress[adminAddress].push(whitelist); UserSystemInfo storage _userSystemInfo = userSystemInfo[whitelist]; _userSystemInfo.straightAddress = adminAddress; _userSystemInfo.whiteAddress = whitelist; _userSystemInfo.adminAddress = adminAddress; _userSystemInfo.whitelist = true; emit TobeWhitelistAddress(whitelist, adminAddress); } // -------------------- Resonance api ----------------// function referralPeople(address userAddress,address referralAddress) public onlyResonance() { UserSystemInfo storage _userSystemInfo = userSystemInfo[userAddress]; _userSystemInfo.straightAddress = referralAddress; _userSystemInfo.whiteAddress = userSystemInfo[referralAddress].whiteAddress; _userSystemInfo.adminAddress = userSystemInfo[referralAddress].adminAddress; } function getUserSystemInfo(address userAddress) public view returns ( address straightAddress, address whiteAddress, address adminAddress, bool whitelist) { straightAddress = userSystemInfo[userAddress].straightAddress; whiteAddress = userSystemInfo[userAddress].whiteAddress; adminAddress = userSystemInfo[userAddress].adminAddress; whitelist = userSystemInfo[userAddress].whitelist; } function getUserreferralAddress(address userAddress) public view onlyResonance() returns (address ) { return userSystemInfo[userAddress].straightAddress; } // -------------------- Owner api ----------------// function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; } // -------------------- Admin api ---------------- // // set whitelist close function setWhitelistTime(bool off) public onlyAdmin() { whitelistTime = off; } function getWhitelistTime() public view returns (bool) { return whitelistTime; } // get all whitelist by admin address function getAdminWhitelistAddress(address adminx) public view returns (address[] memory) { return whitelistAddress[adminx]; } // check if the user is whitelist function isWhitelistAddress(address user) public view returns (bool) { return userSystemInfo[user].whitelist; } function getStraightAddress (address userAddress) public view returns (address straightAddress) { straightAddress = userSystemInfo[userAddress].straightAddress; } }
setWhitelistTime
function setWhitelistTime(bool off) public onlyAdmin() { whitelistTime = off; }
// -------------------- Admin api ---------------- // // set whitelist close
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 4417, 4530 ] }
9,032
Resonance
TeamRewards.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
TeamRewards
contract TeamRewards { // -------------------- mapping ------------------------ // mapping(address => UserSystemInfo) public userSystemInfo;// user system information mapping mapping(address => address[]) public whitelistAddress; // Whitelist addresses defined at the beginning of the project // -------------------- array ------------------------ // address[5] internal admin = [address(0x8434750c01D702c9cfabb3b7C5AA2774Ee67C90D), address(0xD8e79f0D2592311E740Ff097FFb0a7eaa8cb506a), address(0x740beb9fa9CCC6e971f90c25C5D5CC77063a722D), address(0x1b5bbac599f1313dB3E8061A0A65608f62897B0C), address(0x6Fd6dF175B97d2E6D651b536761e0d36b33A9495)]; // -------------------- variate ------------------------ // address public resonanceAddress; address public owner; bool public whitelistTime; // -------------------- event ------------------------ // event TobeWhitelistAddress(address indexed user, address adminAddress); // -------------------- structure ------------------------ // // user system information struct UserSystemInfo { address userAddress; // user address address straightAddress; // straight Address address whiteAddress; // whiteList Address address adminAddress; // admin Address bool whitelist; // if whitelist } constructor() public{ whitelistTime = true; owner = msg.sender; } // -------------------- modifier ------------------------ // modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyAdmin () { address adminAddress = msg.sender; require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier mustAdmin (address adminAddress){ require(adminAddress != address(0)); require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier onlyResonance (){ require(msg.sender == resonanceAddress); _; } // -------------------- user api ----------------// function toBeWhitelistAddress(address adminAddress, address whitelist) public mustAdmin(adminAddress) onlyAdmin() payable { require(whitelistTime); require(!userSystemInfo[whitelist].whitelist); whitelistAddress[adminAddress].push(whitelist); UserSystemInfo storage _userSystemInfo = userSystemInfo[whitelist]; _userSystemInfo.straightAddress = adminAddress; _userSystemInfo.whiteAddress = whitelist; _userSystemInfo.adminAddress = adminAddress; _userSystemInfo.whitelist = true; emit TobeWhitelistAddress(whitelist, adminAddress); } // -------------------- Resonance api ----------------// function referralPeople(address userAddress,address referralAddress) public onlyResonance() { UserSystemInfo storage _userSystemInfo = userSystemInfo[userAddress]; _userSystemInfo.straightAddress = referralAddress; _userSystemInfo.whiteAddress = userSystemInfo[referralAddress].whiteAddress; _userSystemInfo.adminAddress = userSystemInfo[referralAddress].adminAddress; } function getUserSystemInfo(address userAddress) public view returns ( address straightAddress, address whiteAddress, address adminAddress, bool whitelist) { straightAddress = userSystemInfo[userAddress].straightAddress; whiteAddress = userSystemInfo[userAddress].whiteAddress; adminAddress = userSystemInfo[userAddress].adminAddress; whitelist = userSystemInfo[userAddress].whitelist; } function getUserreferralAddress(address userAddress) public view onlyResonance() returns (address ) { return userSystemInfo[userAddress].straightAddress; } // -------------------- Owner api ----------------// function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; } // -------------------- Admin api ---------------- // // set whitelist close function setWhitelistTime(bool off) public onlyAdmin() { whitelistTime = off; } function getWhitelistTime() public view returns (bool) { return whitelistTime; } // get all whitelist by admin address function getAdminWhitelistAddress(address adminx) public view returns (address[] memory) { return whitelistAddress[adminx]; } // check if the user is whitelist function isWhitelistAddress(address user) public view returns (bool) { return userSystemInfo[user].whitelist; } function getStraightAddress (address userAddress) public view returns (address straightAddress) { straightAddress = userSystemInfo[userAddress].straightAddress; } }
getAdminWhitelistAddress
function getAdminWhitelistAddress(address adminx) public view returns (address[] memory) { return whitelistAddress[adminx]; }
// get all whitelist by admin address
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 4698, 4862 ] }
9,033
Resonance
TeamRewards.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
TeamRewards
contract TeamRewards { // -------------------- mapping ------------------------ // mapping(address => UserSystemInfo) public userSystemInfo;// user system information mapping mapping(address => address[]) public whitelistAddress; // Whitelist addresses defined at the beginning of the project // -------------------- array ------------------------ // address[5] internal admin = [address(0x8434750c01D702c9cfabb3b7C5AA2774Ee67C90D), address(0xD8e79f0D2592311E740Ff097FFb0a7eaa8cb506a), address(0x740beb9fa9CCC6e971f90c25C5D5CC77063a722D), address(0x1b5bbac599f1313dB3E8061A0A65608f62897B0C), address(0x6Fd6dF175B97d2E6D651b536761e0d36b33A9495)]; // -------------------- variate ------------------------ // address public resonanceAddress; address public owner; bool public whitelistTime; // -------------------- event ------------------------ // event TobeWhitelistAddress(address indexed user, address adminAddress); // -------------------- structure ------------------------ // // user system information struct UserSystemInfo { address userAddress; // user address address straightAddress; // straight Address address whiteAddress; // whiteList Address address adminAddress; // admin Address bool whitelist; // if whitelist } constructor() public{ whitelistTime = true; owner = msg.sender; } // -------------------- modifier ------------------------ // modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyAdmin () { address adminAddress = msg.sender; require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier mustAdmin (address adminAddress){ require(adminAddress != address(0)); require(adminAddress == admin[0] || adminAddress == admin[1] || adminAddress == admin[2] || adminAddress == admin[3] || adminAddress == admin[4]); _; } modifier onlyResonance (){ require(msg.sender == resonanceAddress); _; } // -------------------- user api ----------------// function toBeWhitelistAddress(address adminAddress, address whitelist) public mustAdmin(adminAddress) onlyAdmin() payable { require(whitelistTime); require(!userSystemInfo[whitelist].whitelist); whitelistAddress[adminAddress].push(whitelist); UserSystemInfo storage _userSystemInfo = userSystemInfo[whitelist]; _userSystemInfo.straightAddress = adminAddress; _userSystemInfo.whiteAddress = whitelist; _userSystemInfo.adminAddress = adminAddress; _userSystemInfo.whitelist = true; emit TobeWhitelistAddress(whitelist, adminAddress); } // -------------------- Resonance api ----------------// function referralPeople(address userAddress,address referralAddress) public onlyResonance() { UserSystemInfo storage _userSystemInfo = userSystemInfo[userAddress]; _userSystemInfo.straightAddress = referralAddress; _userSystemInfo.whiteAddress = userSystemInfo[referralAddress].whiteAddress; _userSystemInfo.adminAddress = userSystemInfo[referralAddress].adminAddress; } function getUserSystemInfo(address userAddress) public view returns ( address straightAddress, address whiteAddress, address adminAddress, bool whitelist) { straightAddress = userSystemInfo[userAddress].straightAddress; whiteAddress = userSystemInfo[userAddress].whiteAddress; adminAddress = userSystemInfo[userAddress].adminAddress; whitelist = userSystemInfo[userAddress].whitelist; } function getUserreferralAddress(address userAddress) public view onlyResonance() returns (address ) { return userSystemInfo[userAddress].straightAddress; } // -------------------- Owner api ----------------// function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; } // -------------------- Admin api ---------------- // // set whitelist close function setWhitelistTime(bool off) public onlyAdmin() { whitelistTime = off; } function getWhitelistTime() public view returns (bool) { return whitelistTime; } // get all whitelist by admin address function getAdminWhitelistAddress(address adminx) public view returns (address[] memory) { return whitelistAddress[adminx]; } // check if the user is whitelist function isWhitelistAddress(address user) public view returns (bool) { return userSystemInfo[user].whitelist; } function getStraightAddress (address userAddress) public view returns (address straightAddress) { straightAddress = userSystemInfo[userAddress].straightAddress; } }
isWhitelistAddress
function isWhitelistAddress(address user) public view returns (bool) { return userSystemInfo[user].whitelist; }
// check if the user is whitelist
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 4904, 5054 ] }
9,034
EURTToken
EURTToken.sol
0x307a736bab7976302f630ab151314981c5924569
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
totalSupply
function totalSupply() constant returns (uint256 supply) {}
/// @return total amount of tokens
NatSpecSingleLine
v0.4.25+commit.59dbf8f1
bzzr://67e066c39fb5580c197d0b04ff918c0f1aeaa4504915a869b531098cd118b3eb
{ "func_code_index": [ 60, 124 ] }
9,035
EURTToken
EURTToken.sol
0x307a736bab7976302f630ab151314981c5924569
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
balanceOf
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @param _owner The address from which the balance will be retrieved /// @return The balance
NatSpecSingleLine
v0.4.25+commit.59dbf8f1
bzzr://67e066c39fb5580c197d0b04ff918c0f1aeaa4504915a869b531098cd118b3eb
{ "func_code_index": [ 232, 309 ] }
9,036
EURTToken
EURTToken.sol
0x307a736bab7976302f630ab151314981c5924569
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
transfer
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not
NatSpecSingleLine
v0.4.25+commit.59dbf8f1
bzzr://67e066c39fb5580c197d0b04ff918c0f1aeaa4504915a869b531098cd118b3eb
{ "func_code_index": [ 546, 623 ] }
9,037
EURTToken
EURTToken.sol
0x307a736bab7976302f630ab151314981c5924569
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
transferFrom
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not
NatSpecSingleLine
v0.4.25+commit.59dbf8f1
bzzr://67e066c39fb5580c197d0b04ff918c0f1aeaa4504915a869b531098cd118b3eb
{ "func_code_index": [ 946, 1042 ] }
9,038
EURTToken
EURTToken.sol
0x307a736bab7976302f630ab151314981c5924569
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
approve
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not
NatSpecSingleLine
v0.4.25+commit.59dbf8f1
bzzr://67e066c39fb5580c197d0b04ff918c0f1aeaa4504915a869b531098cd118b3eb
{ "func_code_index": [ 1326, 1407 ] }
9,039
EURTToken
EURTToken.sol
0x307a736bab7976302f630ab151314981c5924569
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
allowance
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
/// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent
NatSpecSingleLine
v0.4.25+commit.59dbf8f1
bzzr://67e066c39fb5580c197d0b04ff918c0f1aeaa4504915a869b531098cd118b3eb
{ "func_code_index": [ 1615, 1712 ] }
9,040
EURTToken
EURTToken.sol
0x307a736bab7976302f630ab151314981c5924569
Solidity
EURTToken
contract EURTToken is StandardToken { function () { //if ether is sent to this address, send it back. throw; } /* Public variables of the token */ /* NOTE: The following variables are OPTIONAL vanities. One does not have to include them. They allow one to customise the token contract & in no way influences the core functionality. Some wallets/interfaces might not even bother to look at this information. */ string public name; //fancy name: eg Simon Bucks uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether. string public symbol; //An identifier: eg SBX string public version = 'H1.0'; //human 0.1 standard. Just an arbitrary versioning scheme. function EURTToken( ) { balances[msg.sender] = 1000000000000000000000000000; // Give the creator all initial tokens totalSupply = 1000000000000000000000000000; // Update total supply name = "EURT"; // Set the name for display purposes decimals = 18; // Amount of decimals for display purposes symbol = "EURT"; // Set the symbol for display purposes } /* Approves and then calls the receiving contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this. //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead. if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; } return true; } }
EURTToken
function EURTToken( ) { balances[msg.sender] = 1000000000000000000000000000; // Give the creator all initial tokens totalSupply = 1000000000000000000000000000; // Update total supply name = "EURT"; // Set the name for display purposes decimals = 18; // Amount of decimals for display purposes symbol = "EURT"; // Set the symbol for display purposes }
//human 0.1 standard. Just an arbitrary versioning scheme.
LineComment
v0.4.25+commit.59dbf8f1
bzzr://67e066c39fb5580c197d0b04ff918c0f1aeaa4504915a869b531098cd118b3eb
{ "func_code_index": [ 918, 1460 ] }
9,041
EURTToken
EURTToken.sol
0x307a736bab7976302f630ab151314981c5924569
Solidity
EURTToken
contract EURTToken is StandardToken { function () { //if ether is sent to this address, send it back. throw; } /* Public variables of the token */ /* NOTE: The following variables are OPTIONAL vanities. One does not have to include them. They allow one to customise the token contract & in no way influences the core functionality. Some wallets/interfaces might not even bother to look at this information. */ string public name; //fancy name: eg Simon Bucks uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether. string public symbol; //An identifier: eg SBX string public version = 'H1.0'; //human 0.1 standard. Just an arbitrary versioning scheme. function EURTToken( ) { balances[msg.sender] = 1000000000000000000000000000; // Give the creator all initial tokens totalSupply = 1000000000000000000000000000; // Update total supply name = "EURT"; // Set the name for display purposes decimals = 18; // Amount of decimals for display purposes symbol = "EURT"; // Set the symbol for display purposes } /* Approves and then calls the receiving contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this. //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead. if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; } return true; } }
approveAndCall
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this. //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead. if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; } return true; }
/* Approves and then calls the receiving contract */
Comment
v0.4.25+commit.59dbf8f1
bzzr://67e066c39fb5580c197d0b04ff918c0f1aeaa4504915a869b531098cd118b3eb
{ "func_code_index": [ 1521, 2326 ] }
9,042
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
tokenSelling
function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; }
/** * @return tokenSelling_ the token being sold */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 3812, 3977 ] }
9,043
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
wallet
function wallet() external view override returns (address wallet_) { wallet_ = _wallet; }
/** * @return wallet_ the address where funds are collected */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 4056, 4161 ] }
9,044
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
paymentTokens
function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; }
/** * @return paymentTokens_ the payment tokens */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 4228, 4406 ] }
9,045
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
rate
function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); }
/** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 4564, 4972 ] }
9,046
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
lotSize
function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); }
/** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 5107, 5400 ] }
9,047
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
maxLots
function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; }
/** * @return maxLots_ maximum number of lots for token being sold */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 5486, 5604 ] }
9,048
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
weiRaisedFor
function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); }
/** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 5728, 5921 ] }
9,049
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
isPaymentToken
function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; }
/** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 6063, 6387 ] }
9,050
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
getTokenAmount
function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); }
/** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 6678, 7064 ] }
9,051
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
getWeiAmount
function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); }
/** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 7394, 8042 ] }
9,052
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
buyTokens
function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); }
/** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 8169, 8308 ] }
9,053
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
buyTokensFor
function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); }
/** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 8493, 8687 ] }
9,054
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_buyTokensFor
function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); }
/** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 9049, 10643 ] }
9,055
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_weiRaisedFor
function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; }
/** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 10767, 11198 ] }
9,056
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_rate
function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; }
/** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 11356, 11524 ] }
9,057
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_lotSize
function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; }
/** * @return lotSize_ lot size of token being sold */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 11595, 11756 ] }
9,058
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_preValidatePurchase
function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks }
/** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 12407, 12648 ] }
9,059
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_postValidatePurchase
function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks }
/** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 13052, 13294 ] }
9,060
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_deliverTokens
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); }
// https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code
LineComment
v0.7.6+commit.7338295f
{ "func_code_index": [ 13692, 13876 ] }
9,061
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_processPurchase
function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); }
/** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 14138, 14304 ] }
9,062
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_updatePurchasingState
function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks }
/** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 14683, 14921 ] }
9,063
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_getTokenAmount
function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); }
/** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 15146, 15369 ] }
9,064
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_getWeiAmount
function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); }
/** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 15699, 16050 ] }
9,065
LaunchpadCrowdsaleWithVesting
contracts/Crowdsale.sol
0x6557d383b209fc901c57da8dffd15e2689e789ed
Solidity
Crowdsale
contract Crowdsale is ReentrancyGuard, ICrowdsale { using SafeMath for uint256; using SafeERC20 for IERC20; uint256 public constant MAX_NUM_PAYMENT_TOKENS = 10; uint256 public constant TOKEN_MAX_DECIMALS = 18; uint256 public constant TOKEN_SELLING_SCALE = 10**TOKEN_MAX_DECIMALS; // Amount of tokens sold uint256 public tokensSold; // The token being sold // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address private _tokenSelling; // Lot size and maximum number of lots for token being sold LotsInfo private _lotsInfo; // Payment tokens // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names address[] private _paymentTokens; // Payment token decimals // https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-are-too-similar // slither-disable-next-line similar-names mapping(address => uint256) private _paymentDecimals; // Indicates whether ERC20 token is acceptable for payment mapping(address => bool) private _isPaymentTokens; // Address where funds are collected address private _wallet; // How many weis one token costs for each ERC20 payment token mapping(address => uint256) private _rates; // Amount of wei raised for each payment token mapping(address => uint256) private _weiRaised; /** * @dev Rates will denote how many weis one token costs for each ERC20 payment token. * For USDC or USDT payment token which has 6 decimals, minimum rate will * be 1000000000000 which will correspond to a price of USD0.000001 per token. * @param wallet_ Address where collected funds will be forwarded to * @param tokenSelling_ Address of the token being sold * @param lotsInfo Lot size and maximum number of lots for token being sold * @param paymentTokensInfo Addresses, decimals, rates and lot sizes of ERC20 tokens acceptable for payment */ constructor( address wallet_, address tokenSelling_, LotsInfo memory lotsInfo, PaymentTokenInfo[] memory paymentTokensInfo ) { require(wallet_ != address(0), "Crowdsale: zero wallet address"); require( tokenSelling_ != address(0), "Crowdsale: zero token selling address" ); require(lotsInfo.lotSize > 0, "Crowdsale: zero lot size"); require(lotsInfo.maxLots > 0, "Crowdsale: zero max lots"); require(paymentTokensInfo.length > 0, "Crowdsale: zero payment tokens"); require( paymentTokensInfo.length < MAX_NUM_PAYMENT_TOKENS, "Crowdsale: exceed max payment tokens" ); _wallet = wallet_; _tokenSelling = tokenSelling_; _lotsInfo = lotsInfo; for (uint256 i = 0; i < paymentTokensInfo.length; i++) { uint256 paymentDecimal = paymentTokensInfo[i].paymentDecimal; require( paymentDecimal <= TOKEN_MAX_DECIMALS, "Crowdsale: decimals exceed 18" ); address paymentToken = paymentTokensInfo[i].paymentToken; require( paymentToken != address(0), "Crowdsale: zero payment token address" ); uint256 rate_ = paymentTokensInfo[i].rate; require(rate_ > 0, "Crowdsale: zero rate"); _isPaymentTokens[paymentToken] = true; _paymentTokens.push(paymentToken); _paymentDecimals[paymentToken] = paymentDecimal; _rates[paymentToken] = rate_; } } /** * @return tokenSelling_ the token being sold */ function tokenSelling() external view override returns (address tokenSelling_) { tokenSelling_ = _tokenSelling; } /** * @return wallet_ the address where funds are collected */ function wallet() external view override returns (address wallet_) { wallet_ = _wallet; } /** * @return paymentTokens_ the payment tokens */ function paymentTokens() external view override returns (address[] memory paymentTokens_) { paymentTokens_ = _paymentTokens; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function rate(address paymentToken) external view override returns (uint256 rate_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); rate_ = _rate(paymentToken); } /** * @param beneficiary Address performing the token purchase * @return lotSize_ lot size of token being sold */ function lotSize(address beneficiary) public view override returns (uint256 lotSize_) { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); lotSize_ = _lotSize(beneficiary); } /** * @return maxLots_ maximum number of lots for token being sold */ function maxLots() external view override returns (uint256 maxLots_) { maxLots_ = _lotsInfo.maxLots; } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function weiRaisedFor(address paymentToken) external view override returns (uint256 weiRaised_) { weiRaised_ = _weiRaisedFor(paymentToken); } /** * @param paymentToken ERC20 payment token address * @return isPaymentToken_ whether token is accepted for payment */ function isPaymentToken(address paymentToken) public view override returns (bool isPaymentToken_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); isPaymentToken_ = _isPaymentTokens[paymentToken]; } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return tokenAmount Number of tokens being sold that will be purchased */ function getTokenAmount(uint256 lots, address beneficiary) external view override returns (uint256 tokenAmount) { require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); tokenAmount = _getTokenAmount(lots, beneficiary); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) external view override returns (uint256 weiAmount) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); } /** * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokens(address paymentToken, uint256 lots) external override { _buyTokensFor(msg.sender, paymentToken, lots); } /** * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) external override { _buyTokensFor(beneficiary, paymentToken, lots); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * This function has a non-reentrancy guard, so it shouldn't be called by * another `nonReentrant` function. * @param beneficiary Recipient of the token purchase * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold */ function _buyTokensFor( address beneficiary, address paymentToken, uint256 lots ) internal nonReentrant { require( beneficiary != address(0), "Crowdsale: zero beneficiary address" ); require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require(lots > 0, "Crowdsale: zero lots"); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); // calculate token amount to be created uint256 tokenAmount = _getTokenAmount(lots, beneficiary); // calculate wei amount to transfer to wallet uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary); _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount); // update state _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount); tokensSold = tokensSold.add(tokenAmount); _updatePurchasingState( beneficiary, paymentToken, weiAmount, tokenAmount ); emit TokensPurchased( msg.sender, beneficiary, paymentToken, lots, weiAmount, tokenAmount ); _processPurchase(beneficiary, tokenAmount); _forwardFunds(paymentToken, weiAmount); _postValidatePurchase( beneficiary, paymentToken, weiAmount, tokenAmount ); } /** * @param paymentToken ERC20 payment token address * @return weiRaised_ the amount of wei raised */ function _weiRaisedFor(address paymentToken) internal view virtual returns (uint256 weiRaised_) { require( paymentToken != address(0), "Crowdsale: zero payment token address" ); require( isPaymentToken(paymentToken), "Crowdsale: payment token unaccepted" ); weiRaised_ = _weiRaised[paymentToken]; } /** * @param paymentToken ERC20 payment token address * @return rate_ how many weis one token costs for specified ERC20 payment token */ function _rate(address paymentToken) internal view virtual returns (uint256 rate_) { rate_ = _rates[paymentToken]; } /** * @return lotSize_ lot size of token being sold */ function _lotSize(address) internal view virtual returns (uint256 lotSize_) { lotSize_ = _lotsInfo.lotSize; } /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use `super` in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _preValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo/rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _postValidatePurchase( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal view virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted */ // https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code // slither-disable-next-line dead-code function _deliverTokens(address beneficiary, uint256 tokenAmount) internal virtual { IERC20(_tokenSelling).safeTransfer(beneficiary, tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased */ function _processPurchase(address beneficiary, uint256 tokenAmount) internal virtual { _deliverTokens(beneficiary, tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param paymentToken ERC20 payment token address * @param weiAmount Amount in wei of ERC20 payment token * @param tokenAmount Number of tokens to be purchased */ function _updatePurchasingState( address beneficiary, address paymentToken, uint256 weiAmount, uint256 tokenAmount ) internal virtual { // solhint-disable-previous-line no-empty-blocks } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param lots Number of lots of token being sold * @return tokenAmount Number of tokens that will be purchased */ function _getTokenAmount(uint256 lots, address) internal view virtual returns (uint256 tokenAmount) { tokenAmount = lots.mul(_lotsInfo.lotSize).mul(TOKEN_SELLING_SCALE); } /** * @dev Override to extend the way in which payment token is converted to tokens. * @param paymentToken ERC20 payment token address * @param lots Number of lots of token being sold * @param beneficiary Address receiving the tokens * @return weiAmount Amount in wei of ERC20 payment token */ function _getWeiAmount( address paymentToken, uint256 lots, address beneficiary ) internal view virtual returns (uint256 weiAmount) { uint256 rate_ = _rate(paymentToken); uint256 tokenAmount = _getTokenAmount(lots, beneficiary); weiAmount = tokenAmount.mul(rate_).div(TOKEN_SELLING_SCALE); } /** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */ function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); } }
/** * @title Crowdsale * @author Enjinstarter * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ERC20 tokens. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is *not* intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. */
NatSpecMultiLine
_forwardFunds
function _forwardFunds(address paymentToken, uint256 weiAmount) internal virtual { uint256 amount = weiAmount; if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) { uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub( _paymentDecimals[paymentToken] ); amount = weiAmount.div(10**decimalsDiff); } IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount); }
/** * @dev Determines how ERC20 payment token is stored/forwarded on purchases. */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 16149, 16635 ] }
9,066
AdvisorsVesting
contracts/vault/AdvisorsVesting.sol
0xf7ac1fb0b22eab86c1a459d4779b7039a37e7d24
Solidity
AdvisorsVesting
contract AdvisorsVesting is BasicVault { using SafeERC20 for IERC20; using SafeMath for uint256; /*** PRE-DEPLOYMENT CONFIGURED CONSTANTS */ uint256 private constant ALLOCATION = 1500000 ether; // 180 days after the crowdsale starts uint256 private constant CLIFF_DURATION = 180 days; // A default time, doesn't really matter uint256 private constant DEFAULT_RELEASETIME = 9999 days; // 360 days of vesting duration uint256 private constant VESTING_DURATION = 360 days; mapping(address=>uint256) private _initialBalances; /** * @notice Create a vesting vault for investors * @dev Upon the creation of the contract, the ownership should be transferred to the * crowdsale contract. * @param token The address of the token contract * @param crowdsale The address of the crowdsale contract * @param updateTime The timestamp before which information is still updatable in this * contract * @param newOwner The address of the new owner of this contract. */ /* solhint-disable */ constructor( IERC20 token, address crowdsale, uint256 updateTime, address newOwner ) public BasicVault(token, crowdsale, true, updateTime, updateTime.add(CLIFF_DURATION)) { require(updateTime == IIvoCrowdsale(crowdsale).startingTime(), "Update time not correct"); roleSetup(newOwner); } /* solhint-enable */ /** * @notice Check if the maximum allocation has been reached * @dev Revert if the allocated amount has been reached/exceeded * @param additional The amount of token to be added. */ modifier capNotReached(uint256 additional) { require(totalBalance().add(additional) <= ALLOCATION, "exceed the maximum allocation"); _; } /** * @notice Add advisors in batch. * @param amounts Amounts of token purchased * @param beneficiaries Recipients of the token purchase */ // solhint-disable-next-line function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts) external { uint256 length = amounts.length; require(beneficiaries.length == length, "length !="); require(length <= 256, "To long, please consider shorten the array"); for (uint256 i = 0; i < length; i++) { receiveFor(beneficiaries[i], amounts[i]); } } /** OVERRIDE * @notice Let token owner to get the other tokens accidentally sent to this token address. * @dev Before it reaches the release time, the vault can keep the allocated amount of * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND, * the allocated amount of tokens stays in the SAFT vault during that period. Once the * SEED round ends, this vault can only hold max. totalBalance. * @param tokenToBeRecovered address of the token to be recovered. */ function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner { // only if the token is not the IVO token uint256 balance = tokenToBeRecovered.balanceOf(address(this)); if (tokenToBeRecovered == this.token()) { if (block.timestamp <= this.updateTime()) { tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION)); } else { tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance())); } } else { tokenToBeRecovered.safeTransfer(owner(), balance); } } /** * @notice Give back the balance of a beneficiary before vesting * @param beneficiary The address of the beneficiary * @return The balance of the beneficiary */ function initialBalanceOf(address beneficiary) public view returns (uint256) { return _initialBalances[beneficiary]; } /** * @notice Adding investors to the vesting contract * @dev An INVAO manager can do so before the SEED-ROUND sale ends * (a.k.a the start of the crowdsale) * @param beneficiary The actual token owner once it gets released * @param value The amount of token associated to the beneficiary */ function receiveFor(address beneficiary, uint256 value) public capNotReached(value) { _initialBalances[beneficiary] = _initialBalances[beneficiary].add(value); super.receiveFor(beneficiary, value); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary. */ function release() public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(msg.sender); _releaseFor(msg.sender, releasedAmount); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary, who is differnt from the * msg.sender * @param account The account address for whom the vault releases the IVO token. */ function releaseFor(address account) public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(account); _releaseFor(account, releasedAmount); } /** * @notice Directly transfer the ownership to an address of Invao managing team * @dev This new owner is also the manage of the contract. * @param newOwner The address of the contract's new owner */ function roleSetup(address newOwner) internal { addManager(newOwner); super.roleSetup(newOwner); } /** * @notice calculate the amount of tokens ready to be released * @param account The address of the advisor. * @return The amount to be released per account at the moment of calling */ function getAmountToBeReleased(address account) internal view returns (uint256) { uint256 timeFromUpdate = block.timestamp.sub(updateTime()); if (timeFromUpdate < VESTING_DURATION) { return _initialBalances[account].mul(timeFromUpdate).div(VESTING_DURATION) .sub(_initialBalances[account].sub(balanceOf(account))); } else { return balanceOf(account); } } }
batchReceiveFor
function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts) external { uint256 length = amounts.length; require(beneficiaries.length == length, "length !="); require(length <= 256, "To long, please consider shorten the array"); for (uint256 i = 0; i < length; i++) { receiveFor(beneficiaries[i], amounts[i]); } }
// solhint-disable-next-line
LineComment
v0.5.11+commit.c082d0b4
GNU LGPLv3
bzzr://f0cc3205291ab34efd3c6af7d5dd654a2ef2691ac0fc506dbea37a456a863509
{ "func_code_index": [ 2097, 2518 ] }
9,067
AdvisorsVesting
contracts/vault/AdvisorsVesting.sol
0xf7ac1fb0b22eab86c1a459d4779b7039a37e7d24
Solidity
AdvisorsVesting
contract AdvisorsVesting is BasicVault { using SafeERC20 for IERC20; using SafeMath for uint256; /*** PRE-DEPLOYMENT CONFIGURED CONSTANTS */ uint256 private constant ALLOCATION = 1500000 ether; // 180 days after the crowdsale starts uint256 private constant CLIFF_DURATION = 180 days; // A default time, doesn't really matter uint256 private constant DEFAULT_RELEASETIME = 9999 days; // 360 days of vesting duration uint256 private constant VESTING_DURATION = 360 days; mapping(address=>uint256) private _initialBalances; /** * @notice Create a vesting vault for investors * @dev Upon the creation of the contract, the ownership should be transferred to the * crowdsale contract. * @param token The address of the token contract * @param crowdsale The address of the crowdsale contract * @param updateTime The timestamp before which information is still updatable in this * contract * @param newOwner The address of the new owner of this contract. */ /* solhint-disable */ constructor( IERC20 token, address crowdsale, uint256 updateTime, address newOwner ) public BasicVault(token, crowdsale, true, updateTime, updateTime.add(CLIFF_DURATION)) { require(updateTime == IIvoCrowdsale(crowdsale).startingTime(), "Update time not correct"); roleSetup(newOwner); } /* solhint-enable */ /** * @notice Check if the maximum allocation has been reached * @dev Revert if the allocated amount has been reached/exceeded * @param additional The amount of token to be added. */ modifier capNotReached(uint256 additional) { require(totalBalance().add(additional) <= ALLOCATION, "exceed the maximum allocation"); _; } /** * @notice Add advisors in batch. * @param amounts Amounts of token purchased * @param beneficiaries Recipients of the token purchase */ // solhint-disable-next-line function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts) external { uint256 length = amounts.length; require(beneficiaries.length == length, "length !="); require(length <= 256, "To long, please consider shorten the array"); for (uint256 i = 0; i < length; i++) { receiveFor(beneficiaries[i], amounts[i]); } } /** OVERRIDE * @notice Let token owner to get the other tokens accidentally sent to this token address. * @dev Before it reaches the release time, the vault can keep the allocated amount of * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND, * the allocated amount of tokens stays in the SAFT vault during that period. Once the * SEED round ends, this vault can only hold max. totalBalance. * @param tokenToBeRecovered address of the token to be recovered. */ function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner { // only if the token is not the IVO token uint256 balance = tokenToBeRecovered.balanceOf(address(this)); if (tokenToBeRecovered == this.token()) { if (block.timestamp <= this.updateTime()) { tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION)); } else { tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance())); } } else { tokenToBeRecovered.safeTransfer(owner(), balance); } } /** * @notice Give back the balance of a beneficiary before vesting * @param beneficiary The address of the beneficiary * @return The balance of the beneficiary */ function initialBalanceOf(address beneficiary) public view returns (uint256) { return _initialBalances[beneficiary]; } /** * @notice Adding investors to the vesting contract * @dev An INVAO manager can do so before the SEED-ROUND sale ends * (a.k.a the start of the crowdsale) * @param beneficiary The actual token owner once it gets released * @param value The amount of token associated to the beneficiary */ function receiveFor(address beneficiary, uint256 value) public capNotReached(value) { _initialBalances[beneficiary] = _initialBalances[beneficiary].add(value); super.receiveFor(beneficiary, value); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary. */ function release() public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(msg.sender); _releaseFor(msg.sender, releasedAmount); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary, who is differnt from the * msg.sender * @param account The account address for whom the vault releases the IVO token. */ function releaseFor(address account) public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(account); _releaseFor(account, releasedAmount); } /** * @notice Directly transfer the ownership to an address of Invao managing team * @dev This new owner is also the manage of the contract. * @param newOwner The address of the contract's new owner */ function roleSetup(address newOwner) internal { addManager(newOwner); super.roleSetup(newOwner); } /** * @notice calculate the amount of tokens ready to be released * @param account The address of the advisor. * @return The amount to be released per account at the moment of calling */ function getAmountToBeReleased(address account) internal view returns (uint256) { uint256 timeFromUpdate = block.timestamp.sub(updateTime()); if (timeFromUpdate < VESTING_DURATION) { return _initialBalances[account].mul(timeFromUpdate).div(VESTING_DURATION) .sub(_initialBalances[account].sub(balanceOf(account))); } else { return balanceOf(account); } } }
reclaimToken
function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner { // only if the token is not the IVO token uint256 balance = tokenToBeRecovered.balanceOf(address(this)); if (tokenToBeRecovered == this.token()) { if (block.timestamp <= this.updateTime()) { tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION)); } else { tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance())); } } else { tokenToBeRecovered.safeTransfer(owner(), balance); } }
/** OVERRIDE * @notice Let token owner to get the other tokens accidentally sent to this token address. * @dev Before it reaches the release time, the vault can keep the allocated amount of * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND, * the allocated amount of tokens stays in the SAFT vault during that period. Once the * SEED round ends, this vault can only hold max. totalBalance. * @param tokenToBeRecovered address of the token to be recovered. */
NatSpecMultiLine
v0.5.11+commit.c082d0b4
GNU LGPLv3
bzzr://f0cc3205291ab34efd3c6af7d5dd654a2ef2691ac0fc506dbea37a456a863509
{ "func_code_index": [ 3062, 3681 ] }
9,068
AdvisorsVesting
contracts/vault/AdvisorsVesting.sol
0xf7ac1fb0b22eab86c1a459d4779b7039a37e7d24
Solidity
AdvisorsVesting
contract AdvisorsVesting is BasicVault { using SafeERC20 for IERC20; using SafeMath for uint256; /*** PRE-DEPLOYMENT CONFIGURED CONSTANTS */ uint256 private constant ALLOCATION = 1500000 ether; // 180 days after the crowdsale starts uint256 private constant CLIFF_DURATION = 180 days; // A default time, doesn't really matter uint256 private constant DEFAULT_RELEASETIME = 9999 days; // 360 days of vesting duration uint256 private constant VESTING_DURATION = 360 days; mapping(address=>uint256) private _initialBalances; /** * @notice Create a vesting vault for investors * @dev Upon the creation of the contract, the ownership should be transferred to the * crowdsale contract. * @param token The address of the token contract * @param crowdsale The address of the crowdsale contract * @param updateTime The timestamp before which information is still updatable in this * contract * @param newOwner The address of the new owner of this contract. */ /* solhint-disable */ constructor( IERC20 token, address crowdsale, uint256 updateTime, address newOwner ) public BasicVault(token, crowdsale, true, updateTime, updateTime.add(CLIFF_DURATION)) { require(updateTime == IIvoCrowdsale(crowdsale).startingTime(), "Update time not correct"); roleSetup(newOwner); } /* solhint-enable */ /** * @notice Check if the maximum allocation has been reached * @dev Revert if the allocated amount has been reached/exceeded * @param additional The amount of token to be added. */ modifier capNotReached(uint256 additional) { require(totalBalance().add(additional) <= ALLOCATION, "exceed the maximum allocation"); _; } /** * @notice Add advisors in batch. * @param amounts Amounts of token purchased * @param beneficiaries Recipients of the token purchase */ // solhint-disable-next-line function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts) external { uint256 length = amounts.length; require(beneficiaries.length == length, "length !="); require(length <= 256, "To long, please consider shorten the array"); for (uint256 i = 0; i < length; i++) { receiveFor(beneficiaries[i], amounts[i]); } } /** OVERRIDE * @notice Let token owner to get the other tokens accidentally sent to this token address. * @dev Before it reaches the release time, the vault can keep the allocated amount of * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND, * the allocated amount of tokens stays in the SAFT vault during that period. Once the * SEED round ends, this vault can only hold max. totalBalance. * @param tokenToBeRecovered address of the token to be recovered. */ function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner { // only if the token is not the IVO token uint256 balance = tokenToBeRecovered.balanceOf(address(this)); if (tokenToBeRecovered == this.token()) { if (block.timestamp <= this.updateTime()) { tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION)); } else { tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance())); } } else { tokenToBeRecovered.safeTransfer(owner(), balance); } } /** * @notice Give back the balance of a beneficiary before vesting * @param beneficiary The address of the beneficiary * @return The balance of the beneficiary */ function initialBalanceOf(address beneficiary) public view returns (uint256) { return _initialBalances[beneficiary]; } /** * @notice Adding investors to the vesting contract * @dev An INVAO manager can do so before the SEED-ROUND sale ends * (a.k.a the start of the crowdsale) * @param beneficiary The actual token owner once it gets released * @param value The amount of token associated to the beneficiary */ function receiveFor(address beneficiary, uint256 value) public capNotReached(value) { _initialBalances[beneficiary] = _initialBalances[beneficiary].add(value); super.receiveFor(beneficiary, value); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary. */ function release() public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(msg.sender); _releaseFor(msg.sender, releasedAmount); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary, who is differnt from the * msg.sender * @param account The account address for whom the vault releases the IVO token. */ function releaseFor(address account) public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(account); _releaseFor(account, releasedAmount); } /** * @notice Directly transfer the ownership to an address of Invao managing team * @dev This new owner is also the manage of the contract. * @param newOwner The address of the contract's new owner */ function roleSetup(address newOwner) internal { addManager(newOwner); super.roleSetup(newOwner); } /** * @notice calculate the amount of tokens ready to be released * @param account The address of the advisor. * @return The amount to be released per account at the moment of calling */ function getAmountToBeReleased(address account) internal view returns (uint256) { uint256 timeFromUpdate = block.timestamp.sub(updateTime()); if (timeFromUpdate < VESTING_DURATION) { return _initialBalances[account].mul(timeFromUpdate).div(VESTING_DURATION) .sub(_initialBalances[account].sub(balanceOf(account))); } else { return balanceOf(account); } } }
initialBalanceOf
function initialBalanceOf(address beneficiary) public view returns (uint256) { return _initialBalances[beneficiary]; }
/** * @notice Give back the balance of a beneficiary before vesting * @param beneficiary The address of the beneficiary * @return The balance of the beneficiary */
NatSpecMultiLine
v0.5.11+commit.c082d0b4
GNU LGPLv3
bzzr://f0cc3205291ab34efd3c6af7d5dd654a2ef2691ac0fc506dbea37a456a863509
{ "func_code_index": [ 3878, 4015 ] }
9,069
AdvisorsVesting
contracts/vault/AdvisorsVesting.sol
0xf7ac1fb0b22eab86c1a459d4779b7039a37e7d24
Solidity
AdvisorsVesting
contract AdvisorsVesting is BasicVault { using SafeERC20 for IERC20; using SafeMath for uint256; /*** PRE-DEPLOYMENT CONFIGURED CONSTANTS */ uint256 private constant ALLOCATION = 1500000 ether; // 180 days after the crowdsale starts uint256 private constant CLIFF_DURATION = 180 days; // A default time, doesn't really matter uint256 private constant DEFAULT_RELEASETIME = 9999 days; // 360 days of vesting duration uint256 private constant VESTING_DURATION = 360 days; mapping(address=>uint256) private _initialBalances; /** * @notice Create a vesting vault for investors * @dev Upon the creation of the contract, the ownership should be transferred to the * crowdsale contract. * @param token The address of the token contract * @param crowdsale The address of the crowdsale contract * @param updateTime The timestamp before which information is still updatable in this * contract * @param newOwner The address of the new owner of this contract. */ /* solhint-disable */ constructor( IERC20 token, address crowdsale, uint256 updateTime, address newOwner ) public BasicVault(token, crowdsale, true, updateTime, updateTime.add(CLIFF_DURATION)) { require(updateTime == IIvoCrowdsale(crowdsale).startingTime(), "Update time not correct"); roleSetup(newOwner); } /* solhint-enable */ /** * @notice Check if the maximum allocation has been reached * @dev Revert if the allocated amount has been reached/exceeded * @param additional The amount of token to be added. */ modifier capNotReached(uint256 additional) { require(totalBalance().add(additional) <= ALLOCATION, "exceed the maximum allocation"); _; } /** * @notice Add advisors in batch. * @param amounts Amounts of token purchased * @param beneficiaries Recipients of the token purchase */ // solhint-disable-next-line function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts) external { uint256 length = amounts.length; require(beneficiaries.length == length, "length !="); require(length <= 256, "To long, please consider shorten the array"); for (uint256 i = 0; i < length; i++) { receiveFor(beneficiaries[i], amounts[i]); } } /** OVERRIDE * @notice Let token owner to get the other tokens accidentally sent to this token address. * @dev Before it reaches the release time, the vault can keep the allocated amount of * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND, * the allocated amount of tokens stays in the SAFT vault during that period. Once the * SEED round ends, this vault can only hold max. totalBalance. * @param tokenToBeRecovered address of the token to be recovered. */ function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner { // only if the token is not the IVO token uint256 balance = tokenToBeRecovered.balanceOf(address(this)); if (tokenToBeRecovered == this.token()) { if (block.timestamp <= this.updateTime()) { tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION)); } else { tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance())); } } else { tokenToBeRecovered.safeTransfer(owner(), balance); } } /** * @notice Give back the balance of a beneficiary before vesting * @param beneficiary The address of the beneficiary * @return The balance of the beneficiary */ function initialBalanceOf(address beneficiary) public view returns (uint256) { return _initialBalances[beneficiary]; } /** * @notice Adding investors to the vesting contract * @dev An INVAO manager can do so before the SEED-ROUND sale ends * (a.k.a the start of the crowdsale) * @param beneficiary The actual token owner once it gets released * @param value The amount of token associated to the beneficiary */ function receiveFor(address beneficiary, uint256 value) public capNotReached(value) { _initialBalances[beneficiary] = _initialBalances[beneficiary].add(value); super.receiveFor(beneficiary, value); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary. */ function release() public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(msg.sender); _releaseFor(msg.sender, releasedAmount); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary, who is differnt from the * msg.sender * @param account The account address for whom the vault releases the IVO token. */ function releaseFor(address account) public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(account); _releaseFor(account, releasedAmount); } /** * @notice Directly transfer the ownership to an address of Invao managing team * @dev This new owner is also the manage of the contract. * @param newOwner The address of the contract's new owner */ function roleSetup(address newOwner) internal { addManager(newOwner); super.roleSetup(newOwner); } /** * @notice calculate the amount of tokens ready to be released * @param account The address of the advisor. * @return The amount to be released per account at the moment of calling */ function getAmountToBeReleased(address account) internal view returns (uint256) { uint256 timeFromUpdate = block.timestamp.sub(updateTime()); if (timeFromUpdate < VESTING_DURATION) { return _initialBalances[account].mul(timeFromUpdate).div(VESTING_DURATION) .sub(_initialBalances[account].sub(balanceOf(account))); } else { return balanceOf(account); } } }
receiveFor
function receiveFor(address beneficiary, uint256 value) public capNotReached(value) { _initialBalances[beneficiary] = _initialBalances[beneficiary].add(value); super.receiveFor(beneficiary, value); }
/** * @notice Adding investors to the vesting contract * @dev An INVAO manager can do so before the SEED-ROUND sale ends * (a.k.a the start of the crowdsale) * @param beneficiary The actual token owner once it gets released * @param value The amount of token associated to the beneficiary */
NatSpecMultiLine
v0.5.11+commit.c082d0b4
GNU LGPLv3
bzzr://f0cc3205291ab34efd3c6af7d5dd654a2ef2691ac0fc506dbea37a456a863509
{ "func_code_index": [ 4352, 4603 ] }
9,070
AdvisorsVesting
contracts/vault/AdvisorsVesting.sol
0xf7ac1fb0b22eab86c1a459d4779b7039a37e7d24
Solidity
AdvisorsVesting
contract AdvisorsVesting is BasicVault { using SafeERC20 for IERC20; using SafeMath for uint256; /*** PRE-DEPLOYMENT CONFIGURED CONSTANTS */ uint256 private constant ALLOCATION = 1500000 ether; // 180 days after the crowdsale starts uint256 private constant CLIFF_DURATION = 180 days; // A default time, doesn't really matter uint256 private constant DEFAULT_RELEASETIME = 9999 days; // 360 days of vesting duration uint256 private constant VESTING_DURATION = 360 days; mapping(address=>uint256) private _initialBalances; /** * @notice Create a vesting vault for investors * @dev Upon the creation of the contract, the ownership should be transferred to the * crowdsale contract. * @param token The address of the token contract * @param crowdsale The address of the crowdsale contract * @param updateTime The timestamp before which information is still updatable in this * contract * @param newOwner The address of the new owner of this contract. */ /* solhint-disable */ constructor( IERC20 token, address crowdsale, uint256 updateTime, address newOwner ) public BasicVault(token, crowdsale, true, updateTime, updateTime.add(CLIFF_DURATION)) { require(updateTime == IIvoCrowdsale(crowdsale).startingTime(), "Update time not correct"); roleSetup(newOwner); } /* solhint-enable */ /** * @notice Check if the maximum allocation has been reached * @dev Revert if the allocated amount has been reached/exceeded * @param additional The amount of token to be added. */ modifier capNotReached(uint256 additional) { require(totalBalance().add(additional) <= ALLOCATION, "exceed the maximum allocation"); _; } /** * @notice Add advisors in batch. * @param amounts Amounts of token purchased * @param beneficiaries Recipients of the token purchase */ // solhint-disable-next-line function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts) external { uint256 length = amounts.length; require(beneficiaries.length == length, "length !="); require(length <= 256, "To long, please consider shorten the array"); for (uint256 i = 0; i < length; i++) { receiveFor(beneficiaries[i], amounts[i]); } } /** OVERRIDE * @notice Let token owner to get the other tokens accidentally sent to this token address. * @dev Before it reaches the release time, the vault can keep the allocated amount of * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND, * the allocated amount of tokens stays in the SAFT vault during that period. Once the * SEED round ends, this vault can only hold max. totalBalance. * @param tokenToBeRecovered address of the token to be recovered. */ function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner { // only if the token is not the IVO token uint256 balance = tokenToBeRecovered.balanceOf(address(this)); if (tokenToBeRecovered == this.token()) { if (block.timestamp <= this.updateTime()) { tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION)); } else { tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance())); } } else { tokenToBeRecovered.safeTransfer(owner(), balance); } } /** * @notice Give back the balance of a beneficiary before vesting * @param beneficiary The address of the beneficiary * @return The balance of the beneficiary */ function initialBalanceOf(address beneficiary) public view returns (uint256) { return _initialBalances[beneficiary]; } /** * @notice Adding investors to the vesting contract * @dev An INVAO manager can do so before the SEED-ROUND sale ends * (a.k.a the start of the crowdsale) * @param beneficiary The actual token owner once it gets released * @param value The amount of token associated to the beneficiary */ function receiveFor(address beneficiary, uint256 value) public capNotReached(value) { _initialBalances[beneficiary] = _initialBalances[beneficiary].add(value); super.receiveFor(beneficiary, value); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary. */ function release() public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(msg.sender); _releaseFor(msg.sender, releasedAmount); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary, who is differnt from the * msg.sender * @param account The account address for whom the vault releases the IVO token. */ function releaseFor(address account) public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(account); _releaseFor(account, releasedAmount); } /** * @notice Directly transfer the ownership to an address of Invao managing team * @dev This new owner is also the manage of the contract. * @param newOwner The address of the contract's new owner */ function roleSetup(address newOwner) internal { addManager(newOwner); super.roleSetup(newOwner); } /** * @notice calculate the amount of tokens ready to be released * @param account The address of the advisor. * @return The amount to be released per account at the moment of calling */ function getAmountToBeReleased(address account) internal view returns (uint256) { uint256 timeFromUpdate = block.timestamp.sub(updateTime()); if (timeFromUpdate < VESTING_DURATION) { return _initialBalances[account].mul(timeFromUpdate).div(VESTING_DURATION) .sub(_initialBalances[account].sub(balanceOf(account))); } else { return balanceOf(account); } } }
release
function release() public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(msg.sender); _releaseFor(msg.sender, releasedAmount); }
/** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary. */
NatSpecMultiLine
v0.5.11+commit.c082d0b4
GNU LGPLv3
bzzr://f0cc3205291ab34efd3c6af7d5dd654a2ef2691ac0fc506dbea37a456a863509
{ "func_code_index": [ 4698, 4871 ] }
9,071
AdvisorsVesting
contracts/vault/AdvisorsVesting.sol
0xf7ac1fb0b22eab86c1a459d4779b7039a37e7d24
Solidity
AdvisorsVesting
contract AdvisorsVesting is BasicVault { using SafeERC20 for IERC20; using SafeMath for uint256; /*** PRE-DEPLOYMENT CONFIGURED CONSTANTS */ uint256 private constant ALLOCATION = 1500000 ether; // 180 days after the crowdsale starts uint256 private constant CLIFF_DURATION = 180 days; // A default time, doesn't really matter uint256 private constant DEFAULT_RELEASETIME = 9999 days; // 360 days of vesting duration uint256 private constant VESTING_DURATION = 360 days; mapping(address=>uint256) private _initialBalances; /** * @notice Create a vesting vault for investors * @dev Upon the creation of the contract, the ownership should be transferred to the * crowdsale contract. * @param token The address of the token contract * @param crowdsale The address of the crowdsale contract * @param updateTime The timestamp before which information is still updatable in this * contract * @param newOwner The address of the new owner of this contract. */ /* solhint-disable */ constructor( IERC20 token, address crowdsale, uint256 updateTime, address newOwner ) public BasicVault(token, crowdsale, true, updateTime, updateTime.add(CLIFF_DURATION)) { require(updateTime == IIvoCrowdsale(crowdsale).startingTime(), "Update time not correct"); roleSetup(newOwner); } /* solhint-enable */ /** * @notice Check if the maximum allocation has been reached * @dev Revert if the allocated amount has been reached/exceeded * @param additional The amount of token to be added. */ modifier capNotReached(uint256 additional) { require(totalBalance().add(additional) <= ALLOCATION, "exceed the maximum allocation"); _; } /** * @notice Add advisors in batch. * @param amounts Amounts of token purchased * @param beneficiaries Recipients of the token purchase */ // solhint-disable-next-line function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts) external { uint256 length = amounts.length; require(beneficiaries.length == length, "length !="); require(length <= 256, "To long, please consider shorten the array"); for (uint256 i = 0; i < length; i++) { receiveFor(beneficiaries[i], amounts[i]); } } /** OVERRIDE * @notice Let token owner to get the other tokens accidentally sent to this token address. * @dev Before it reaches the release time, the vault can keep the allocated amount of * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND, * the allocated amount of tokens stays in the SAFT vault during that period. Once the * SEED round ends, this vault can only hold max. totalBalance. * @param tokenToBeRecovered address of the token to be recovered. */ function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner { // only if the token is not the IVO token uint256 balance = tokenToBeRecovered.balanceOf(address(this)); if (tokenToBeRecovered == this.token()) { if (block.timestamp <= this.updateTime()) { tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION)); } else { tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance())); } } else { tokenToBeRecovered.safeTransfer(owner(), balance); } } /** * @notice Give back the balance of a beneficiary before vesting * @param beneficiary The address of the beneficiary * @return The balance of the beneficiary */ function initialBalanceOf(address beneficiary) public view returns (uint256) { return _initialBalances[beneficiary]; } /** * @notice Adding investors to the vesting contract * @dev An INVAO manager can do so before the SEED-ROUND sale ends * (a.k.a the start of the crowdsale) * @param beneficiary The actual token owner once it gets released * @param value The amount of token associated to the beneficiary */ function receiveFor(address beneficiary, uint256 value) public capNotReached(value) { _initialBalances[beneficiary] = _initialBalances[beneficiary].add(value); super.receiveFor(beneficiary, value); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary. */ function release() public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(msg.sender); _releaseFor(msg.sender, releasedAmount); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary, who is differnt from the * msg.sender * @param account The account address for whom the vault releases the IVO token. */ function releaseFor(address account) public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(account); _releaseFor(account, releasedAmount); } /** * @notice Directly transfer the ownership to an address of Invao managing team * @dev This new owner is also the manage of the contract. * @param newOwner The address of the contract's new owner */ function roleSetup(address newOwner) internal { addManager(newOwner); super.roleSetup(newOwner); } /** * @notice calculate the amount of tokens ready to be released * @param account The address of the advisor. * @return The amount to be released per account at the moment of calling */ function getAmountToBeReleased(address account) internal view returns (uint256) { uint256 timeFromUpdate = block.timestamp.sub(updateTime()); if (timeFromUpdate < VESTING_DURATION) { return _initialBalances[account].mul(timeFromUpdate).div(VESTING_DURATION) .sub(_initialBalances[account].sub(balanceOf(account))); } else { return balanceOf(account); } } }
releaseFor
function releaseFor(address account) public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(account); _releaseFor(account, releasedAmount); }
/** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary, who is differnt from the * msg.sender * @param account The account address for whom the vault releases the IVO token. */
NatSpecMultiLine
v0.5.11+commit.c082d0b4
GNU LGPLv3
bzzr://f0cc3205291ab34efd3c6af7d5dd654a2ef2691ac0fc506dbea37a456a863509
{ "func_code_index": [ 5094, 5279 ] }
9,072
AdvisorsVesting
contracts/vault/AdvisorsVesting.sol
0xf7ac1fb0b22eab86c1a459d4779b7039a37e7d24
Solidity
AdvisorsVesting
contract AdvisorsVesting is BasicVault { using SafeERC20 for IERC20; using SafeMath for uint256; /*** PRE-DEPLOYMENT CONFIGURED CONSTANTS */ uint256 private constant ALLOCATION = 1500000 ether; // 180 days after the crowdsale starts uint256 private constant CLIFF_DURATION = 180 days; // A default time, doesn't really matter uint256 private constant DEFAULT_RELEASETIME = 9999 days; // 360 days of vesting duration uint256 private constant VESTING_DURATION = 360 days; mapping(address=>uint256) private _initialBalances; /** * @notice Create a vesting vault for investors * @dev Upon the creation of the contract, the ownership should be transferred to the * crowdsale contract. * @param token The address of the token contract * @param crowdsale The address of the crowdsale contract * @param updateTime The timestamp before which information is still updatable in this * contract * @param newOwner The address of the new owner of this contract. */ /* solhint-disable */ constructor( IERC20 token, address crowdsale, uint256 updateTime, address newOwner ) public BasicVault(token, crowdsale, true, updateTime, updateTime.add(CLIFF_DURATION)) { require(updateTime == IIvoCrowdsale(crowdsale).startingTime(), "Update time not correct"); roleSetup(newOwner); } /* solhint-enable */ /** * @notice Check if the maximum allocation has been reached * @dev Revert if the allocated amount has been reached/exceeded * @param additional The amount of token to be added. */ modifier capNotReached(uint256 additional) { require(totalBalance().add(additional) <= ALLOCATION, "exceed the maximum allocation"); _; } /** * @notice Add advisors in batch. * @param amounts Amounts of token purchased * @param beneficiaries Recipients of the token purchase */ // solhint-disable-next-line function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts) external { uint256 length = amounts.length; require(beneficiaries.length == length, "length !="); require(length <= 256, "To long, please consider shorten the array"); for (uint256 i = 0; i < length; i++) { receiveFor(beneficiaries[i], amounts[i]); } } /** OVERRIDE * @notice Let token owner to get the other tokens accidentally sent to this token address. * @dev Before it reaches the release time, the vault can keep the allocated amount of * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND, * the allocated amount of tokens stays in the SAFT vault during that period. Once the * SEED round ends, this vault can only hold max. totalBalance. * @param tokenToBeRecovered address of the token to be recovered. */ function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner { // only if the token is not the IVO token uint256 balance = tokenToBeRecovered.balanceOf(address(this)); if (tokenToBeRecovered == this.token()) { if (block.timestamp <= this.updateTime()) { tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION)); } else { tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance())); } } else { tokenToBeRecovered.safeTransfer(owner(), balance); } } /** * @notice Give back the balance of a beneficiary before vesting * @param beneficiary The address of the beneficiary * @return The balance of the beneficiary */ function initialBalanceOf(address beneficiary) public view returns (uint256) { return _initialBalances[beneficiary]; } /** * @notice Adding investors to the vesting contract * @dev An INVAO manager can do so before the SEED-ROUND sale ends * (a.k.a the start of the crowdsale) * @param beneficiary The actual token owner once it gets released * @param value The amount of token associated to the beneficiary */ function receiveFor(address beneficiary, uint256 value) public capNotReached(value) { _initialBalances[beneficiary] = _initialBalances[beneficiary].add(value); super.receiveFor(beneficiary, value); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary. */ function release() public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(msg.sender); _releaseFor(msg.sender, releasedAmount); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary, who is differnt from the * msg.sender * @param account The account address for whom the vault releases the IVO token. */ function releaseFor(address account) public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(account); _releaseFor(account, releasedAmount); } /** * @notice Directly transfer the ownership to an address of Invao managing team * @dev This new owner is also the manage of the contract. * @param newOwner The address of the contract's new owner */ function roleSetup(address newOwner) internal { addManager(newOwner); super.roleSetup(newOwner); } /** * @notice calculate the amount of tokens ready to be released * @param account The address of the advisor. * @return The amount to be released per account at the moment of calling */ function getAmountToBeReleased(address account) internal view returns (uint256) { uint256 timeFromUpdate = block.timestamp.sub(updateTime()); if (timeFromUpdate < VESTING_DURATION) { return _initialBalances[account].mul(timeFromUpdate).div(VESTING_DURATION) .sub(_initialBalances[account].sub(balanceOf(account))); } else { return balanceOf(account); } } }
roleSetup
function roleSetup(address newOwner) internal { addManager(newOwner); super.roleSetup(newOwner); }
/** * @notice Directly transfer the ownership to an address of Invao managing team * @dev This new owner is also the manage of the contract. * @param newOwner The address of the contract's new owner */
NatSpecMultiLine
v0.5.11+commit.c082d0b4
GNU LGPLv3
bzzr://f0cc3205291ab34efd3c6af7d5dd654a2ef2691ac0fc506dbea37a456a863509
{ "func_code_index": [ 5513, 5639 ] }
9,073
AdvisorsVesting
contracts/vault/AdvisorsVesting.sol
0xf7ac1fb0b22eab86c1a459d4779b7039a37e7d24
Solidity
AdvisorsVesting
contract AdvisorsVesting is BasicVault { using SafeERC20 for IERC20; using SafeMath for uint256; /*** PRE-DEPLOYMENT CONFIGURED CONSTANTS */ uint256 private constant ALLOCATION = 1500000 ether; // 180 days after the crowdsale starts uint256 private constant CLIFF_DURATION = 180 days; // A default time, doesn't really matter uint256 private constant DEFAULT_RELEASETIME = 9999 days; // 360 days of vesting duration uint256 private constant VESTING_DURATION = 360 days; mapping(address=>uint256) private _initialBalances; /** * @notice Create a vesting vault for investors * @dev Upon the creation of the contract, the ownership should be transferred to the * crowdsale contract. * @param token The address of the token contract * @param crowdsale The address of the crowdsale contract * @param updateTime The timestamp before which information is still updatable in this * contract * @param newOwner The address of the new owner of this contract. */ /* solhint-disable */ constructor( IERC20 token, address crowdsale, uint256 updateTime, address newOwner ) public BasicVault(token, crowdsale, true, updateTime, updateTime.add(CLIFF_DURATION)) { require(updateTime == IIvoCrowdsale(crowdsale).startingTime(), "Update time not correct"); roleSetup(newOwner); } /* solhint-enable */ /** * @notice Check if the maximum allocation has been reached * @dev Revert if the allocated amount has been reached/exceeded * @param additional The amount of token to be added. */ modifier capNotReached(uint256 additional) { require(totalBalance().add(additional) <= ALLOCATION, "exceed the maximum allocation"); _; } /** * @notice Add advisors in batch. * @param amounts Amounts of token purchased * @param beneficiaries Recipients of the token purchase */ // solhint-disable-next-line function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts) external { uint256 length = amounts.length; require(beneficiaries.length == length, "length !="); require(length <= 256, "To long, please consider shorten the array"); for (uint256 i = 0; i < length; i++) { receiveFor(beneficiaries[i], amounts[i]); } } /** OVERRIDE * @notice Let token owner to get the other tokens accidentally sent to this token address. * @dev Before it reaches the release time, the vault can keep the allocated amount of * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND, * the allocated amount of tokens stays in the SAFT vault during that period. Once the * SEED round ends, this vault can only hold max. totalBalance. * @param tokenToBeRecovered address of the token to be recovered. */ function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner { // only if the token is not the IVO token uint256 balance = tokenToBeRecovered.balanceOf(address(this)); if (tokenToBeRecovered == this.token()) { if (block.timestamp <= this.updateTime()) { tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION)); } else { tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance())); } } else { tokenToBeRecovered.safeTransfer(owner(), balance); } } /** * @notice Give back the balance of a beneficiary before vesting * @param beneficiary The address of the beneficiary * @return The balance of the beneficiary */ function initialBalanceOf(address beneficiary) public view returns (uint256) { return _initialBalances[beneficiary]; } /** * @notice Adding investors to the vesting contract * @dev An INVAO manager can do so before the SEED-ROUND sale ends * (a.k.a the start of the crowdsale) * @param beneficiary The actual token owner once it gets released * @param value The amount of token associated to the beneficiary */ function receiveFor(address beneficiary, uint256 value) public capNotReached(value) { _initialBalances[beneficiary] = _initialBalances[beneficiary].add(value); super.receiveFor(beneficiary, value); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary. */ function release() public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(msg.sender); _releaseFor(msg.sender, releasedAmount); } /** OVERRIDE * @notice Transfers tokens held by the vault to beneficiary, who is differnt from the * msg.sender * @param account The account address for whom the vault releases the IVO token. */ function releaseFor(address account) public readyToRelease { uint256 releasedAmount = getAmountToBeReleased(account); _releaseFor(account, releasedAmount); } /** * @notice Directly transfer the ownership to an address of Invao managing team * @dev This new owner is also the manage of the contract. * @param newOwner The address of the contract's new owner */ function roleSetup(address newOwner) internal { addManager(newOwner); super.roleSetup(newOwner); } /** * @notice calculate the amount of tokens ready to be released * @param account The address of the advisor. * @return The amount to be released per account at the moment of calling */ function getAmountToBeReleased(address account) internal view returns (uint256) { uint256 timeFromUpdate = block.timestamp.sub(updateTime()); if (timeFromUpdate < VESTING_DURATION) { return _initialBalances[account].mul(timeFromUpdate).div(VESTING_DURATION) .sub(_initialBalances[account].sub(balanceOf(account))); } else { return balanceOf(account); } } }
getAmountToBeReleased
function getAmountToBeReleased(address account) internal view returns (uint256) { uint256 timeFromUpdate = block.timestamp.sub(updateTime()); if (timeFromUpdate < VESTING_DURATION) { return _initialBalances[account].mul(timeFromUpdate).div(VESTING_DURATION) .sub(_initialBalances[account].sub(balanceOf(account))); } else { return balanceOf(account); } }
/** * @notice calculate the amount of tokens ready to be released * @param account The address of the advisor. * @return The amount to be released per account at the moment of calling */
NatSpecMultiLine
v0.5.11+commit.c082d0b4
GNU LGPLv3
bzzr://f0cc3205291ab34efd3c6af7d5dd654a2ef2691ac0fc506dbea37a456a863509
{ "func_code_index": [ 5858, 6297 ] }
9,074
SetTokenCreator
contracts/protocol/SetTokenCreator.sol
0x1e91d53b38f6de5180a98c4c9e396dd50a3eabd7
Solidity
SetTokenCreator
contract SetTokenCreator { using AddressArrayUtils for address[]; /* ============ Events ============ */ event SetTokenCreated(address indexed _setToken, address _manager, string _name, string _symbol); /* ============ State Variables ============ */ // Instance of the controller smart contract IController public controller; /* ============ Functions ============ */ /** * @param _controller Instance of the controller */ constructor(IController _controller) { controller = _controller; } /** * Creates a SetToken smart contract and registers the SetToken with the controller. The SetTokens are composed * of positions that are instantiated as DEFAULT (positionState = 0) state. * * @param _components List of addresses of components for initial Positions * @param _units List of units. Each unit is the # of components per 10^18 of a SetToken * @param _modules List of modules to enable. All modules must be approved by the Controller * @param _manager Address of the manager * @param _name Name of the SetToken * @param _symbol Symbol of the SetToken * @return address Address of the newly created SetToken */ function create( address[] memory _components, int256[] memory _units, address[] memory _modules, address _manager, string memory _name, string memory _symbol ) external returns (address) { require(_components.length > 0, "Must have at least 1 component"); require(_components.length == _units.length, "Component and unit lengths must be the same"); require(!_components.hasDuplicate(), "Components must not have a duplicate"); require(_modules.length > 0, "Must have at least 1 module"); require(_manager != address(0), "Manager must not be empty"); for (uint256 i = 0; i < _components.length; i++) { require(_components[i] != address(0), "Component must not be null address"); require(_units[i] > 0, "Units must be greater than 0"); } for (uint256 j = 0; j < _modules.length; j++) { require(controller.isModule(_modules[j]), "Must be enabled module"); } // Creates a new SetToken instance SetToken setToken = new SetToken( _components, _units, _modules, controller, _manager, _name, _symbol ); // Registers Set with controller controller.addSet(address(setToken)); emit SetTokenCreated(address(setToken), _manager, _name, _symbol); return address(setToken); } }
/** * @title SetTokenCreator * @author Set Protocol * * SetTokenCreator is a smart contract used to deploy new SetToken contracts. The SetTokenCreator * is a Factory contract that is enabled by the controller to create and register new SetTokens. */
NatSpecMultiLine
create
function create( address[] memory _components, int256[] memory _units, address[] memory _modules, address _manager, string memory _name, string memory _symbol ) external returns (address) { require(_components.length > 0, "Must have at least 1 component"); require(_components.length == _units.length, "Component and unit lengths must be the same"); require(!_components.hasDuplicate(), "Components must not have a duplicate"); require(_modules.length > 0, "Must have at least 1 module"); require(_manager != address(0), "Manager must not be empty"); for (uint256 i = 0; i < _components.length; i++) { require(_components[i] != address(0), "Component must not be null address"); require(_units[i] > 0, "Units must be greater than 0"); } for (uint256 j = 0; j < _modules.length; j++) { require(controller.isModule(_modules[j]), "Must be enabled module"); } // Creates a new SetToken instance SetToken setToken = new SetToken( _components, _units, _modules, controller, _manager, _name, _symbol ); // Registers Set with controller controller.addSet(address(setToken)); emit SetTokenCreated(address(setToken), _manager, _name, _symbol); return address(setToken); }
/** * Creates a SetToken smart contract and registers the SetToken with the controller. The SetTokens are composed * of positions that are instantiated as DEFAULT (positionState = 0) state. * * @param _components List of addresses of components for initial Positions * @param _units List of units. Each unit is the # of components per 10^18 of a SetToken * @param _modules List of modules to enable. All modules must be approved by the Controller * @param _manager Address of the manager * @param _name Name of the SetToken * @param _symbol Symbol of the SetToken * @return address Address of the newly created SetToken */
NatSpecMultiLine
v0.7.6+commit.7338295f
None
{ "func_code_index": [ 1303, 2624 ] }
9,075
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
addTerminator
function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; }
//添加终结者(主合约调用)
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 1380, 1894 ] }
9,076
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
modifyTerminatorReward
function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; }
//用户提取奖励(主合约调用)
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 1918, 2224 ] }
9,077
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
reInvestTerminatorReward
function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; }
//用户复投(主合约调用)
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 2244, 2552 ] }
9,078
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
addRecodeTerminator
function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; }
//添加用户信息记录,等待触发终结者(内部调用)
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 2585, 3355 ] }
9,079
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
addRecodeToTerminatorArray
function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); }
//产生终结者,将终结者信息写入并计算奖励(内部调用)
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 3389, 4115 ] }
9,080
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
addCallOwner
function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; }
//添加主合约调用权限(合约拥有者调用)
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 4144, 4275 ] }
9,081
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
getAllTerminatorAddress
function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; }
//根据区块高度获取获取所有获得终结者奖励地址
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 4305, 4484 ] }
9,082
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
getLatestTerminatorInfo
function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } }
//获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 4526, 5379 ] }
9,083
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
getTerminatorRewardAmount
function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; }
//获取可提现奖励金额
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 5397, 5625 ] }
9,084
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
getUserTerminatorRewardInfo
function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; }
//获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 5663, 5825 ] }
9,085
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
getAllTerminatorBlockNumber
function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; }
//获取所有产生终结者的区块数组
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 5848, 5988 ] }
9,086
Resonance
Terminator.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Terminator
contract Terminator { address terminatorOwner; //合约拥有者 address callOwner; //部分方法允许调用者(主合约) struct recodeTerminator { address userAddress; //用户地址 uint256 amountInvest; //用户留存在合约当中的金额 } uint256 public BlockNumber; //区块高度 uint256 public AllTerminatorInvestAmount; //终结者所有用户总投入金额 uint256 public TerminatorRewardPool; //当前终结者奖池金额 uint256 public TerminatorRewardWithdrawPool; //终结者可提现奖池金额 uint256 public signRecodeTerminator; //标记插入位置 recodeTerminator[50] public recodeTerminatorInfo; //终结者记录数组 mapping(address => uint256 [4]) internal terminatorAllReward; //用户总奖励金额和已提取的奖励金额和复投总金额 mapping(uint256 => address[50]) internal blockAllTerminatorAddress; //每个区块有多少终结者 uint256[] internal signBlockHasTerminator; //产生终结者的区块数组 //事件 event AchieveTerminator(uint256 terminatorBlocknumber); //成为终结者 //初始化合约 constructor() public{ terminatorOwner = msg.sender; } //添加终结者(主合约调用) function addTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) public checkCallOwner(msg.sender) { require(amount > 0); require(amountPool > 0); if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { addRecodeToTerminatorArray(BlockNumber); signBlockHasTerminator.push(BlockNumber); } addRecodeTerminator(addr, amount, blockNumber, amountPool); BlockNumber = blockNumber; } //用户提取奖励(主合约调用) function modifyTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][1] += amount; } //用户复投(主合约调用) function reInvestTerminatorReward(address addr, uint256 amount) public checkCallOwner(msg.sender) { require(amount <= terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]); terminatorAllReward[addr][3] += amount; } //添加用户信息记录,等待触发终结者(内部调用) function addRecodeTerminator(address addr, uint256 amount, uint256 blockNumber, uint256 amountPool) internal { recodeTerminator memory t = recodeTerminator(addr, amount); if (blockNumber == BlockNumber) { if (signRecodeTerminator >= 50) { AllTerminatorInvestAmount -= recodeTerminatorInfo[signRecodeTerminator % 50].amountInvest; } recodeTerminatorInfo[signRecodeTerminator % 50] = t; signRecodeTerminator++; AllTerminatorInvestAmount += amount; } else { recodeTerminatorInfo[0] = t; signRecodeTerminator = 1; AllTerminatorInvestAmount = amount; } TerminatorRewardPool = amountPool; } //产生终结者,将终结者信息写入并计算奖励(内部调用) function addRecodeToTerminatorArray(uint256 blockNumber) internal { for (uint256 i = 0; i < 50; i++) { if (i >= signRecodeTerminator) { break; } address userAddress = recodeTerminatorInfo[i].userAddress; uint256 reward = (recodeTerminatorInfo[i].amountInvest) * (TerminatorRewardPool) / (AllTerminatorInvestAmount); blockAllTerminatorAddress[blockNumber][i] = userAddress; terminatorAllReward[userAddress][0] += reward; terminatorAllReward[userAddress][2] = reward; } TerminatorRewardWithdrawPool += TerminatorRewardPool; emit AchieveTerminator(blockNumber); } //添加主合约调用权限(合约拥有者调用) function addCallOwner(address addr) public checkTerminatorOwner(msg.sender) { callOwner = addr; } //根据区块高度获取获取所有获得终结者奖励地址 function getAllTerminatorAddress(uint256 blockNumber) view public returns (address[50] memory) { return blockAllTerminatorAddress[blockNumber]; } //获取最近一次获得终结者区块高度和奖励的所有用户地址和上一次获奖数量 function getLatestTerminatorInfo() view public returns (uint256 blockNumber, address[50] memory addressArray, uint256[50] memory amountArray) { uint256 index = signBlockHasTerminator.length; address[50] memory rewardAddress; uint256[50] memory rewardAmount; if (index <= 0) { return (0, rewardAddress, rewardAmount); } else { uint256 blocks = signBlockHasTerminator[index - 1]; rewardAddress = blockAllTerminatorAddress[blocks]; for (uint256 i = 0; i < 50; i++) { if (rewardAddress[i] == address(0)) { break; } rewardAmount[i] = terminatorAllReward[rewardAddress[i]][2]; } return (blocks, rewardAddress, rewardAmount); } } //获取可提现奖励金额 function getTerminatorRewardAmount(address addr) view public returns (uint256) { return terminatorAllReward[addr][0] - (terminatorAllReward[addr][1] * 100 / 80) - terminatorAllReward[addr][3]; } //获取用户所有奖励金额和已提现金额和上一次获奖金额和复投金额 function getUserTerminatorRewardInfo(address addr) view public returns (uint256[4] memory) { return terminatorAllReward[addr]; } //获取所有产生终结者的区块数组 function getAllTerminatorBlockNumber() view public returns (uint256[] memory){ return signBlockHasTerminator; } //获取当次已提走奖池金额(供主合约调用) function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } } //检查合约拥有者权限 modifier checkTerminatorOwner(address addr) { require(addr == terminatorOwner); _; } //检查合约调用者权限(检查是否是主合约调用) modifier checkCallOwner(address addr) { require(addr == callOwner || addr == terminatorOwner); _; } }
checkBlockWithdrawAmount
function checkBlockWithdrawAmount(uint256 blockNumber) view public returns (uint256) { if (blockNumber >= BlockNumber + 240 && BlockNumber != 0) { return (TerminatorRewardPool + TerminatorRewardWithdrawPool); } else { return (TerminatorRewardWithdrawPool); } }
//获取当次已提走奖池金额(供主合约调用)
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 6016, 6354 ] }
9,087
Cat
Cat.sol
0x44a0ad6e696820fa192a3dcf37d0cc55a45cbc38
Solidity
Cat
contract Cat is LibNote { // --- Auth --- mapping (address => uint) public wards; function rely(address usr) external note auth { wards[usr] = 1; } function deny(address usr) external note auth { wards[usr] = 0; } modifier auth { require(wards[msg.sender] == 1, "Cat/not-authorized"); _; } // --- Data --- struct Ilk { address flip; // Liquidator uint256 chop; // Liquidation Penalty [ray] uint256 lump; // Liquidation Quantity [wad] } mapping (bytes32 => Ilk) public ilks; uint256 public live; VatLike public vat; VowLike public vow; // --- Events --- event Bite( bytes32 indexed ilk, address indexed urn, uint256 ink, uint256 art, uint256 tab, address flip, uint256 id ); // --- Init --- constructor(address vat_) public { wards[msg.sender] = 1; vat = VatLike(vat_); live = 1; } // --- Math --- uint constant ONE = 10 ** 27; function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x); } function rmul(uint x, uint y) internal pure returns (uint z) { z = mul(x, y) / ONE; } function min(uint x, uint y) internal pure returns (uint z) { if (x > y) { z = y; } else { z = x; } } // --- Administration --- function file(bytes32 what, address data) external note auth { if (what == "vow") vow = VowLike(data); else revert("Cat/file-unrecognized-param"); } function file(bytes32 ilk, bytes32 what, uint data) external note auth { if (what == "chop") ilks[ilk].chop = data; else if (what == "lump") ilks[ilk].lump = data; else revert("Cat/file-unrecognized-param"); } function file(bytes32 ilk, bytes32 what, address flip) external note auth { if (what == "flip") { vat.nope(ilks[ilk].flip); ilks[ilk].flip = flip; vat.hope(flip); } else revert("Cat/file-unrecognized-param"); } // --- CDP Liquidation --- function bite(bytes32 ilk, address urn) external returns (uint id) { (, uint rate, uint spot) = vat.ilks(ilk); (uint ink, uint art) = vat.urns(ilk, urn); require(live == 1, "Cat/not-live"); require(spot > 0 && mul(ink, spot) < mul(art, rate), "Cat/not-unsafe"); uint lot = min(ink, ilks[ilk].lump); art = min(art, mul(lot, art) / ink); require(lot <= 2**255 && art <= 2**255, "Cat/overflow"); vat.grab(ilk, urn, address(this), address(vow), -int(lot), -int(art)); vow.fess(mul(art, rate)); id = Kicker(ilks[ilk].flip).kick({ urn: urn , gal: address(vow) , tab: rmul(mul(art, rate), ilks[ilk].chop) , lot: lot , bid: 0 }); emit Bite(ilk, urn, lot, art, mul(art, rate), ilks[ilk].flip, id); } function cage() external note auth { live = 0; } }
file
function file(bytes32 what, address data) external note auth { if (what == "vow") vow = VowLike(data); else revert("Cat/file-unrecognized-param"); }
// --- Administration ---
LineComment
v0.5.12+commit.7709ece9
GNU GPLv3
bzzr://af6e3812015d5a0c72f717f82a7526edebf996fe11ed6934dff264aaf3d973ff
{ "func_code_index": [ 1457, 1633 ] }
9,088
Cat
Cat.sol
0x44a0ad6e696820fa192a3dcf37d0cc55a45cbc38
Solidity
Cat
contract Cat is LibNote { // --- Auth --- mapping (address => uint) public wards; function rely(address usr) external note auth { wards[usr] = 1; } function deny(address usr) external note auth { wards[usr] = 0; } modifier auth { require(wards[msg.sender] == 1, "Cat/not-authorized"); _; } // --- Data --- struct Ilk { address flip; // Liquidator uint256 chop; // Liquidation Penalty [ray] uint256 lump; // Liquidation Quantity [wad] } mapping (bytes32 => Ilk) public ilks; uint256 public live; VatLike public vat; VowLike public vow; // --- Events --- event Bite( bytes32 indexed ilk, address indexed urn, uint256 ink, uint256 art, uint256 tab, address flip, uint256 id ); // --- Init --- constructor(address vat_) public { wards[msg.sender] = 1; vat = VatLike(vat_); live = 1; } // --- Math --- uint constant ONE = 10 ** 27; function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x); } function rmul(uint x, uint y) internal pure returns (uint z) { z = mul(x, y) / ONE; } function min(uint x, uint y) internal pure returns (uint z) { if (x > y) { z = y; } else { z = x; } } // --- Administration --- function file(bytes32 what, address data) external note auth { if (what == "vow") vow = VowLike(data); else revert("Cat/file-unrecognized-param"); } function file(bytes32 ilk, bytes32 what, uint data) external note auth { if (what == "chop") ilks[ilk].chop = data; else if (what == "lump") ilks[ilk].lump = data; else revert("Cat/file-unrecognized-param"); } function file(bytes32 ilk, bytes32 what, address flip) external note auth { if (what == "flip") { vat.nope(ilks[ilk].flip); ilks[ilk].flip = flip; vat.hope(flip); } else revert("Cat/file-unrecognized-param"); } // --- CDP Liquidation --- function bite(bytes32 ilk, address urn) external returns (uint id) { (, uint rate, uint spot) = vat.ilks(ilk); (uint ink, uint art) = vat.urns(ilk, urn); require(live == 1, "Cat/not-live"); require(spot > 0 && mul(ink, spot) < mul(art, rate), "Cat/not-unsafe"); uint lot = min(ink, ilks[ilk].lump); art = min(art, mul(lot, art) / ink); require(lot <= 2**255 && art <= 2**255, "Cat/overflow"); vat.grab(ilk, urn, address(this), address(vow), -int(lot), -int(art)); vow.fess(mul(art, rate)); id = Kicker(ilks[ilk].flip).kick({ urn: urn , gal: address(vow) , tab: rmul(mul(art, rate), ilks[ilk].chop) , lot: lot , bid: 0 }); emit Bite(ilk, urn, lot, art, mul(art, rate), ilks[ilk].flip, id); } function cage() external note auth { live = 0; } }
bite
function bite(bytes32 ilk, address urn) external returns (uint id) { (, uint rate, uint spot) = vat.ilks(ilk); (uint ink, uint art) = vat.urns(ilk, urn); require(live == 1, "Cat/not-live"); require(spot > 0 && mul(ink, spot) < mul(art, rate), "Cat/not-unsafe"); uint lot = min(ink, ilks[ilk].lump); art = min(art, mul(lot, art) / ink); require(lot <= 2**255 && art <= 2**255, "Cat/overflow"); vat.grab(ilk, urn, address(this), address(vow), -int(lot), -int(art)); vow.fess(mul(art, rate)); id = Kicker(ilks[ilk].flip).kick({ urn: urn , gal: address(vow) , tab: rmul(mul(art, rate), ilks[ilk].chop) , lot: lot , bid: 0 }); emit Bite(ilk, urn, lot, art, mul(art, rate), ilks[ilk].flip, id); }
// --- CDP Liquidation ---
LineComment
v0.5.12+commit.7709ece9
GNU GPLv3
bzzr://af6e3812015d5a0c72f717f82a7526edebf996fe11ed6934dff264aaf3d973ff
{ "func_code_index": [ 2202, 3226 ] }
9,089
Resonance
Earnings.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Earnings
contract Earnings { using SafeMath for *; // -------------------- mapping ------------------------ // mapping(address => UserWithdraw) public userWithdraw; // record user withdraw reward information // -------------------- variate ------------------------ // uint8 constant internal percent = 100; uint8 constant internal remain = 20; // Static and dynamic rewards returns remain at 20 percent address public resonanceAddress; address public owner; // -------------------- struct ------------------------ // struct UserWithdraw { uint256 withdrawStraight; // withdraw straight eth amount uint256 withdrawTeam; // withdraw team eth amount uint256 withdrawStatic; // withdraw static eth amount uint256 withdrawTerminator;//withdraw terminator amount uint256 withdrawNode; // withdraw node amount uint256 lockEth; // user lock eth uint256 activateEth; // record user activate eth } constructor() public{ owner = msg.sender; } // -------------------- modifier ------------------------ // modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyResonance (){ require(msg.sender == resonanceAddress); _; } // -------------------- owner api ------------------------ // function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; } // -------------------- Resonance api ------------------------ // // calculate actual reinvest amount, include amount + lockEth function calculateReinvestAmount( address reinvestAddress, uint256 amount, uint256 userAmount, uint8 requireType)//type: 1 => straightEth, 2 => teamEth, 3 => withdrawStatic, 4 => withdrawNode public onlyResonance() returns (uint256) { if (requireType == 1) { require(amount.add((userWithdraw[reinvestAddress].withdrawStatic).mul(100).div(80)) <= userAmount); } else if (requireType == 2) { require(amount.add((userWithdraw[reinvestAddress].withdrawStraight).mul(100).div(80)) <= userAmount.add(amount)); } else if (requireType == 3) { require(amount.add((userWithdraw[reinvestAddress].withdrawTeam).mul(100).div(80)) <= userAmount.add(amount)); } else if (requireType == 5) { require(amount.add((userWithdraw[reinvestAddress].withdrawNode).mul(100).div(80)) <= userAmount); } // userWithdraw[reinvestAddress].lockEth = userWithdraw[reinvestAddress].lockEth.add(amount.mul(remain).div(100));\ uint256 _active = userWithdraw[reinvestAddress].lockEth - userWithdraw[reinvestAddress].activateEth; if (amount > _active) { userWithdraw[reinvestAddress].activateEth += _active; amount = amount.add(_active); } else { userWithdraw[reinvestAddress].activateEth = userWithdraw[reinvestAddress].activateEth.add(amount); amount = amount.mul(2); } return amount; } function routeAddLockEth( address withdrawAddress, uint256 amount, uint256 lockProfits, uint256 userRouteEth, uint256 routeType) public onlyResonance() { if (routeType == 1) { addLockEthStatic(withdrawAddress, amount, lockProfits, userRouteEth); } else if (routeType == 2) { addLockEthStraight(withdrawAddress, amount, userRouteEth); } else if (routeType == 3) { addLockEthTeam(withdrawAddress, amount, userRouteEth); } else if (routeType == 4) { addLockEthTerminator(withdrawAddress, amount, userRouteEth); } else if (routeType == 5) { addLockEthNode(withdrawAddress, amount, userRouteEth); } } function addLockEthStatic(address withdrawAddress, uint256 amount, uint256 lockProfits, uint256 userStatic) internal { require(amount.add(userWithdraw[withdrawAddress].withdrawStatic.mul(100).div(percent - remain)) <= userStatic); userWithdraw[withdrawAddress].lockEth += lockProfits; userWithdraw[withdrawAddress].withdrawStatic += amount.sub(lockProfits); } function addLockEthStraight(address withdrawAddress, uint256 amount, uint256 userStraightEth) internal { require(amount.add(userWithdraw[withdrawAddress].withdrawStraight.mul(100).div(percent - remain)) <= userStraightEth); userWithdraw[withdrawAddress].lockEth += amount.mul(remain).div(100); userWithdraw[withdrawAddress].withdrawStraight += amount.mul(percent - remain).div(100); } function addLockEthTeam(address withdrawAddress, uint256 amount, uint256 userTeamEth) internal { require(amount.add(userWithdraw[withdrawAddress].withdrawTeam.mul(100).div(percent - remain)) <= userTeamEth); userWithdraw[withdrawAddress].lockEth += amount.mul(remain).div(100); userWithdraw[withdrawAddress].withdrawTeam += amount.mul(percent - remain).div(100); } function addLockEthTerminator(address withdrawAddress, uint256 amount, uint256 withdrawAmount) internal { userWithdraw[withdrawAddress].lockEth += amount.mul(remain).div(100); userWithdraw[withdrawAddress].withdrawTerminator += withdrawAmount; } function addLockEthNode(address withdrawAddress, uint256 amount, uint256 userNodeEth) internal { require(amount.add(userWithdraw[withdrawAddress].withdrawNode.mul(100).div(percent - remain)) <= userNodeEth); userWithdraw[withdrawAddress].lockEth += amount.mul(remain).div(100); userWithdraw[withdrawAddress].withdrawNode += amount.mul(percent - remain).div(100); } function addActivateEth(address userAddress, uint256 amount) public onlyResonance() { uint256 _afterFounds = getAfterFounds(userAddress); if (amount > _afterFounds) { userWithdraw[userAddress].activateEth = userWithdraw[userAddress].lockEth; } else { userWithdraw[userAddress].activateEth += amount; } } function changeWithdrawTeamZero(address userAddress) public onlyResonance() { userWithdraw[userAddress].withdrawTeam = 0; } function getWithdrawStraight(address reinvestAddress) public view onlyResonance() returns (uint256) { return userWithdraw[reinvestAddress].withdrawStraight; } function getWithdrawStatic(address reinvestAddress) public view onlyResonance() returns (uint256) { return userWithdraw[reinvestAddress].withdrawStatic; } function getWithdrawTeam(address reinvestAddress) public view onlyResonance() returns (uint256) { return userWithdraw[reinvestAddress].withdrawTeam; } function getWithdrawNode(address reinvestAddress) public view onlyResonance() returns (uint256) { return userWithdraw[reinvestAddress].withdrawNode; } function getAfterFounds(address userAddress) public view onlyResonance() returns (uint256) { return userWithdraw[userAddress].lockEth - userWithdraw[userAddress].activateEth; } function getStaticAfterFounds(address reinvestAddress) public view onlyResonance() returns (uint256, uint256) { return (userWithdraw[reinvestAddress].withdrawStatic, userWithdraw[reinvestAddress].lockEth - userWithdraw[reinvestAddress].activateEth); } function getStaticAfterFoundsTeam(address userAddress) public view onlyResonance() returns (uint256, uint256, uint256) { return (userWithdraw[userAddress].withdrawStatic, userWithdraw[userAddress].lockEth - userWithdraw[userAddress].activateEth, userWithdraw[userAddress].withdrawTeam); } function getUserWithdrawInfo(address reinvestAddress) public view onlyResonance() returns ( uint256 withdrawStraight, uint256 withdrawTeam, uint256 withdrawStatic, uint256 withdrawNode ) { withdrawStraight = userWithdraw[reinvestAddress].withdrawStraight; withdrawTeam = userWithdraw[reinvestAddress].withdrawTeam; withdrawStatic = userWithdraw[reinvestAddress].withdrawStatic; withdrawNode = userWithdraw[reinvestAddress].withdrawNode; } }
allowResonance
function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; }
// -------------------- owner api ------------------------ //
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 1415, 1521 ] }
9,090
Resonance
Earnings.sol
0xd87c7ef38c3eaa2a196db19a5f1338eec123bec9
Solidity
Earnings
contract Earnings { using SafeMath for *; // -------------------- mapping ------------------------ // mapping(address => UserWithdraw) public userWithdraw; // record user withdraw reward information // -------------------- variate ------------------------ // uint8 constant internal percent = 100; uint8 constant internal remain = 20; // Static and dynamic rewards returns remain at 20 percent address public resonanceAddress; address public owner; // -------------------- struct ------------------------ // struct UserWithdraw { uint256 withdrawStraight; // withdraw straight eth amount uint256 withdrawTeam; // withdraw team eth amount uint256 withdrawStatic; // withdraw static eth amount uint256 withdrawTerminator;//withdraw terminator amount uint256 withdrawNode; // withdraw node amount uint256 lockEth; // user lock eth uint256 activateEth; // record user activate eth } constructor() public{ owner = msg.sender; } // -------------------- modifier ------------------------ // modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyResonance (){ require(msg.sender == resonanceAddress); _; } // -------------------- owner api ------------------------ // function allowResonance(address _addr) public onlyOwner() { resonanceAddress = _addr; } // -------------------- Resonance api ------------------------ // // calculate actual reinvest amount, include amount + lockEth function calculateReinvestAmount( address reinvestAddress, uint256 amount, uint256 userAmount, uint8 requireType)//type: 1 => straightEth, 2 => teamEth, 3 => withdrawStatic, 4 => withdrawNode public onlyResonance() returns (uint256) { if (requireType == 1) { require(amount.add((userWithdraw[reinvestAddress].withdrawStatic).mul(100).div(80)) <= userAmount); } else if (requireType == 2) { require(amount.add((userWithdraw[reinvestAddress].withdrawStraight).mul(100).div(80)) <= userAmount.add(amount)); } else if (requireType == 3) { require(amount.add((userWithdraw[reinvestAddress].withdrawTeam).mul(100).div(80)) <= userAmount.add(amount)); } else if (requireType == 5) { require(amount.add((userWithdraw[reinvestAddress].withdrawNode).mul(100).div(80)) <= userAmount); } // userWithdraw[reinvestAddress].lockEth = userWithdraw[reinvestAddress].lockEth.add(amount.mul(remain).div(100));\ uint256 _active = userWithdraw[reinvestAddress].lockEth - userWithdraw[reinvestAddress].activateEth; if (amount > _active) { userWithdraw[reinvestAddress].activateEth += _active; amount = amount.add(_active); } else { userWithdraw[reinvestAddress].activateEth = userWithdraw[reinvestAddress].activateEth.add(amount); amount = amount.mul(2); } return amount; } function routeAddLockEth( address withdrawAddress, uint256 amount, uint256 lockProfits, uint256 userRouteEth, uint256 routeType) public onlyResonance() { if (routeType == 1) { addLockEthStatic(withdrawAddress, amount, lockProfits, userRouteEth); } else if (routeType == 2) { addLockEthStraight(withdrawAddress, amount, userRouteEth); } else if (routeType == 3) { addLockEthTeam(withdrawAddress, amount, userRouteEth); } else if (routeType == 4) { addLockEthTerminator(withdrawAddress, amount, userRouteEth); } else if (routeType == 5) { addLockEthNode(withdrawAddress, amount, userRouteEth); } } function addLockEthStatic(address withdrawAddress, uint256 amount, uint256 lockProfits, uint256 userStatic) internal { require(amount.add(userWithdraw[withdrawAddress].withdrawStatic.mul(100).div(percent - remain)) <= userStatic); userWithdraw[withdrawAddress].lockEth += lockProfits; userWithdraw[withdrawAddress].withdrawStatic += amount.sub(lockProfits); } function addLockEthStraight(address withdrawAddress, uint256 amount, uint256 userStraightEth) internal { require(amount.add(userWithdraw[withdrawAddress].withdrawStraight.mul(100).div(percent - remain)) <= userStraightEth); userWithdraw[withdrawAddress].lockEth += amount.mul(remain).div(100); userWithdraw[withdrawAddress].withdrawStraight += amount.mul(percent - remain).div(100); } function addLockEthTeam(address withdrawAddress, uint256 amount, uint256 userTeamEth) internal { require(amount.add(userWithdraw[withdrawAddress].withdrawTeam.mul(100).div(percent - remain)) <= userTeamEth); userWithdraw[withdrawAddress].lockEth += amount.mul(remain).div(100); userWithdraw[withdrawAddress].withdrawTeam += amount.mul(percent - remain).div(100); } function addLockEthTerminator(address withdrawAddress, uint256 amount, uint256 withdrawAmount) internal { userWithdraw[withdrawAddress].lockEth += amount.mul(remain).div(100); userWithdraw[withdrawAddress].withdrawTerminator += withdrawAmount; } function addLockEthNode(address withdrawAddress, uint256 amount, uint256 userNodeEth) internal { require(amount.add(userWithdraw[withdrawAddress].withdrawNode.mul(100).div(percent - remain)) <= userNodeEth); userWithdraw[withdrawAddress].lockEth += amount.mul(remain).div(100); userWithdraw[withdrawAddress].withdrawNode += amount.mul(percent - remain).div(100); } function addActivateEth(address userAddress, uint256 amount) public onlyResonance() { uint256 _afterFounds = getAfterFounds(userAddress); if (amount > _afterFounds) { userWithdraw[userAddress].activateEth = userWithdraw[userAddress].lockEth; } else { userWithdraw[userAddress].activateEth += amount; } } function changeWithdrawTeamZero(address userAddress) public onlyResonance() { userWithdraw[userAddress].withdrawTeam = 0; } function getWithdrawStraight(address reinvestAddress) public view onlyResonance() returns (uint256) { return userWithdraw[reinvestAddress].withdrawStraight; } function getWithdrawStatic(address reinvestAddress) public view onlyResonance() returns (uint256) { return userWithdraw[reinvestAddress].withdrawStatic; } function getWithdrawTeam(address reinvestAddress) public view onlyResonance() returns (uint256) { return userWithdraw[reinvestAddress].withdrawTeam; } function getWithdrawNode(address reinvestAddress) public view onlyResonance() returns (uint256) { return userWithdraw[reinvestAddress].withdrawNode; } function getAfterFounds(address userAddress) public view onlyResonance() returns (uint256) { return userWithdraw[userAddress].lockEth - userWithdraw[userAddress].activateEth; } function getStaticAfterFounds(address reinvestAddress) public view onlyResonance() returns (uint256, uint256) { return (userWithdraw[reinvestAddress].withdrawStatic, userWithdraw[reinvestAddress].lockEth - userWithdraw[reinvestAddress].activateEth); } function getStaticAfterFoundsTeam(address userAddress) public view onlyResonance() returns (uint256, uint256, uint256) { return (userWithdraw[userAddress].withdrawStatic, userWithdraw[userAddress].lockEth - userWithdraw[userAddress].activateEth, userWithdraw[userAddress].withdrawTeam); } function getUserWithdrawInfo(address reinvestAddress) public view onlyResonance() returns ( uint256 withdrawStraight, uint256 withdrawTeam, uint256 withdrawStatic, uint256 withdrawNode ) { withdrawStraight = userWithdraw[reinvestAddress].withdrawStraight; withdrawTeam = userWithdraw[reinvestAddress].withdrawTeam; withdrawStatic = userWithdraw[reinvestAddress].withdrawStatic; withdrawNode = userWithdraw[reinvestAddress].withdrawNode; } }
calculateReinvestAmount
function calculateReinvestAmount( address reinvestAddress, uint256 amount, uint256 userAmount, uint8 requireType)//type: 1 => straightEth, 2 => teamEth, 3 => withdrawStatic, 4 => withdrawNode public onlyResonance() returns (uint256) { if (requireType == 1) { require(amount.add((userWithdraw[reinvestAddress].withdrawStatic).mul(100).div(80)) <= userAmount); } else if (requireType == 2) { require(amount.add((userWithdraw[reinvestAddress].withdrawStraight).mul(100).div(80)) <= userAmount.add(amount)); } else if (requireType == 3) { require(amount.add((userWithdraw[reinvestAddress].withdrawTeam).mul(100).div(80)) <= userAmount.add(amount)); } else if (requireType == 5) { require(amount.add((userWithdraw[reinvestAddress].withdrawNode).mul(100).div(80)) <= userAmount); } // userWithdraw[reinvestAddress].lockEth = userWithdraw[reinvestAddress].lockEth.add(amount.mul(remain).div(100));\ uint256 _active = userWithdraw[reinvestAddress].lockEth - userWithdraw[reinvestAddress].activateEth; if (amount > _active) { userWithdraw[reinvestAddress].activateEth += _active; amount = amount.add(_active); } else { userWithdraw[reinvestAddress].activateEth = userWithdraw[reinvestAddress].activateEth.add(amount); amount = amount.mul(2); } return amount; }
// -------------------- Resonance api ------------------------ // // calculate actual reinvest amount, include amount + lockEth
LineComment
v0.5.1+commit.c8a2cb62
MIT
bzzr://a1533a2259fca30289db2437294a7f22dad9225667799e7f0acc8ada85f96280
{ "func_code_index": [ 1662, 3191 ] }
9,091
GoodGamePlatform
SafeMath.sol
0x3ac655b147b6e2d2ced40126f6c5956e5467a92b
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } }
/** * @title SafeMath * @dev Math operations with safety checks that throw on error */
NatSpecMultiLine
mul
function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; }
/** * @dev Multiplies two numbers, throws on overflow. */
NatSpecMultiLine
v0.4.25+commit.59dbf8f1
bzzr://ab9f0fe42d9e16b9e57ac46a758e7fa8f126024174b2d499ea997543c325ce05
{ "func_code_index": [ 84, 259 ] }
9,092
GoodGamePlatform
SafeMath.sol
0x3ac655b147b6e2d2ced40126f6c5956e5467a92b
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } }
/** * @title 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 c; }
/** * @dev Integer division of two numbers, truncating the quotient. */
NatSpecMultiLine
v0.4.25+commit.59dbf8f1
bzzr://ab9f0fe42d9e16b9e57ac46a758e7fa8f126024174b2d499ea997543c325ce05
{ "func_code_index": [ 339, 606 ] }
9,093
GoodGamePlatform
SafeMath.sol
0x3ac655b147b6e2d2ced40126f6c5956e5467a92b
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } }
/** * @title 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.25+commit.59dbf8f1
bzzr://ab9f0fe42d9e16b9e57ac46a758e7fa8f126024174b2d499ea997543c325ce05
{ "func_code_index": [ 716, 828 ] }
9,094
GoodGamePlatform
SafeMath.sol
0x3ac655b147b6e2d2ced40126f6c5956e5467a92b
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } }
/** * @title SafeMath * @dev Math operations with safety checks that throw on error */
NatSpecMultiLine
add
function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; }
/** * @dev Adds two numbers, throws on overflow. */
NatSpecMultiLine
v0.4.25+commit.59dbf8f1
bzzr://ab9f0fe42d9e16b9e57ac46a758e7fa8f126024174b2d499ea997543c325ce05
{ "func_code_index": [ 888, 1019 ] }
9,095
GoodGamePlatform
ERC223.sol
0x3ac655b147b6e2d2ced40126f6c5956e5467a92b
Solidity
ERC223Token
contract ERC223Token is ERC223 { using SafeMath for uint; mapping(address => uint) balances; string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; // Function to access name of token . function name() constant returns (string _name) { return name; } // Function to access symbol of token . function symbol() constant returns (string _symbol) { return symbol; } // Function to access decimals of token . function decimals() constant returns (uint8 _decimals) { return decimals; } // Function to access total supply of tokens . function totalSupply() constant returns (uint256 _totalSupply) { return totalSupply; } // Function that is called when a user or another contract wants to transfer funds . function transfer(address _to, uint _value, bytes _data) returns (bool success) { if(isContract(_to)) { return transferToContract(_to, _value, _data); } else { return transferToAddress(_to, _value, _data); } } // Standard function transfer similar to ERC20 transfer with no _data . // Added due to backwards compatibility reasons . function transfer(address _to, uint _value) returns (bool success) { //standard function transfer similar to ERC20 transfer with no _data //added due to backwards compatibility reasons bytes memory empty; if(isContract(_to)) { return transferToContract(_to, _value, empty); } else { return transferToAddress(_to, _value, empty); } } //assemble the given address bytecode. If bytecode exists then the _addr is a contract. function isContract(address _addr) private returns (bool is_contract) { uint length; assembly { //retrieve the size of the code on target address, this needs assembly length := extcodesize(_addr) } if(length>0) { return true; } else { return false; } } //function that is called when transaction target is an address function transferToAddress(address _to, uint _value, bytes _data) private returns (bool success) { if (balanceOf(msg.sender) < _value) revert(); balances[msg.sender] = balanceOf(msg.sender).sub(_value); balances[_to] = balanceOf(_to).add(_value); Transfer(msg.sender, _to, _value); ERC223Transfer(msg.sender, _to, _value, _data); return true; } //function that is called when transaction target is a contract function transferToContract(address _to, uint _value, bytes _data) private returns (bool success) { if (balanceOf(msg.sender) < _value) revert(); balances[msg.sender] = balanceOf(msg.sender).sub(_value); balances[_to] = balanceOf(_to).add(_value); ContractReceiver reciever = ContractReceiver(_to); reciever.tokenFallback(msg.sender, _value, _data); Transfer(msg.sender, _to, _value); ERC223Transfer(msg.sender, _to, _value, _data); return true; } function balanceOf(address _owner) constant returns (uint balance) { return balances[_owner]; } }
name
function name() constant returns (string _name) { return name; }
// Function to access name of token .
LineComment
v0.4.25+commit.59dbf8f1
bzzr://ab9f0fe42d9e16b9e57ac46a758e7fa8f126024174b2d499ea997543c325ce05
{ "func_code_index": [ 242, 316 ] }
9,096
GoodGamePlatform
ERC223.sol
0x3ac655b147b6e2d2ced40126f6c5956e5467a92b
Solidity
ERC223Token
contract ERC223Token is ERC223 { using SafeMath for uint; mapping(address => uint) balances; string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; // Function to access name of token . function name() constant returns (string _name) { return name; } // Function to access symbol of token . function symbol() constant returns (string _symbol) { return symbol; } // Function to access decimals of token . function decimals() constant returns (uint8 _decimals) { return decimals; } // Function to access total supply of tokens . function totalSupply() constant returns (uint256 _totalSupply) { return totalSupply; } // Function that is called when a user or another contract wants to transfer funds . function transfer(address _to, uint _value, bytes _data) returns (bool success) { if(isContract(_to)) { return transferToContract(_to, _value, _data); } else { return transferToAddress(_to, _value, _data); } } // Standard function transfer similar to ERC20 transfer with no _data . // Added due to backwards compatibility reasons . function transfer(address _to, uint _value) returns (bool success) { //standard function transfer similar to ERC20 transfer with no _data //added due to backwards compatibility reasons bytes memory empty; if(isContract(_to)) { return transferToContract(_to, _value, empty); } else { return transferToAddress(_to, _value, empty); } } //assemble the given address bytecode. If bytecode exists then the _addr is a contract. function isContract(address _addr) private returns (bool is_contract) { uint length; assembly { //retrieve the size of the code on target address, this needs assembly length := extcodesize(_addr) } if(length>0) { return true; } else { return false; } } //function that is called when transaction target is an address function transferToAddress(address _to, uint _value, bytes _data) private returns (bool success) { if (balanceOf(msg.sender) < _value) revert(); balances[msg.sender] = balanceOf(msg.sender).sub(_value); balances[_to] = balanceOf(_to).add(_value); Transfer(msg.sender, _to, _value); ERC223Transfer(msg.sender, _to, _value, _data); return true; } //function that is called when transaction target is a contract function transferToContract(address _to, uint _value, bytes _data) private returns (bool success) { if (balanceOf(msg.sender) < _value) revert(); balances[msg.sender] = balanceOf(msg.sender).sub(_value); balances[_to] = balanceOf(_to).add(_value); ContractReceiver reciever = ContractReceiver(_to); reciever.tokenFallback(msg.sender, _value, _data); Transfer(msg.sender, _to, _value); ERC223Transfer(msg.sender, _to, _value, _data); return true; } function balanceOf(address _owner) constant returns (uint balance) { return balances[_owner]; } }
symbol
function symbol() constant returns (string _symbol) { return symbol; }
// Function to access symbol of token .
LineComment
v0.4.25+commit.59dbf8f1
bzzr://ab9f0fe42d9e16b9e57ac46a758e7fa8f126024174b2d499ea997543c325ce05
{ "func_code_index": [ 359, 439 ] }
9,097
GoodGamePlatform
ERC223.sol
0x3ac655b147b6e2d2ced40126f6c5956e5467a92b
Solidity
ERC223Token
contract ERC223Token is ERC223 { using SafeMath for uint; mapping(address => uint) balances; string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; // Function to access name of token . function name() constant returns (string _name) { return name; } // Function to access symbol of token . function symbol() constant returns (string _symbol) { return symbol; } // Function to access decimals of token . function decimals() constant returns (uint8 _decimals) { return decimals; } // Function to access total supply of tokens . function totalSupply() constant returns (uint256 _totalSupply) { return totalSupply; } // Function that is called when a user or another contract wants to transfer funds . function transfer(address _to, uint _value, bytes _data) returns (bool success) { if(isContract(_to)) { return transferToContract(_to, _value, _data); } else { return transferToAddress(_to, _value, _data); } } // Standard function transfer similar to ERC20 transfer with no _data . // Added due to backwards compatibility reasons . function transfer(address _to, uint _value) returns (bool success) { //standard function transfer similar to ERC20 transfer with no _data //added due to backwards compatibility reasons bytes memory empty; if(isContract(_to)) { return transferToContract(_to, _value, empty); } else { return transferToAddress(_to, _value, empty); } } //assemble the given address bytecode. If bytecode exists then the _addr is a contract. function isContract(address _addr) private returns (bool is_contract) { uint length; assembly { //retrieve the size of the code on target address, this needs assembly length := extcodesize(_addr) } if(length>0) { return true; } else { return false; } } //function that is called when transaction target is an address function transferToAddress(address _to, uint _value, bytes _data) private returns (bool success) { if (balanceOf(msg.sender) < _value) revert(); balances[msg.sender] = balanceOf(msg.sender).sub(_value); balances[_to] = balanceOf(_to).add(_value); Transfer(msg.sender, _to, _value); ERC223Transfer(msg.sender, _to, _value, _data); return true; } //function that is called when transaction target is a contract function transferToContract(address _to, uint _value, bytes _data) private returns (bool success) { if (balanceOf(msg.sender) < _value) revert(); balances[msg.sender] = balanceOf(msg.sender).sub(_value); balances[_to] = balanceOf(_to).add(_value); ContractReceiver reciever = ContractReceiver(_to); reciever.tokenFallback(msg.sender, _value, _data); Transfer(msg.sender, _to, _value); ERC223Transfer(msg.sender, _to, _value, _data); return true; } function balanceOf(address _owner) constant returns (uint balance) { return balances[_owner]; } }
decimals
function decimals() constant returns (uint8 _decimals) { return decimals; }
// Function to access decimals of token .
LineComment
v0.4.25+commit.59dbf8f1
bzzr://ab9f0fe42d9e16b9e57ac46a758e7fa8f126024174b2d499ea997543c325ce05
{ "func_code_index": [ 484, 569 ] }
9,098
GoodGamePlatform
ERC223.sol
0x3ac655b147b6e2d2ced40126f6c5956e5467a92b
Solidity
ERC223Token
contract ERC223Token is ERC223 { using SafeMath for uint; mapping(address => uint) balances; string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; // Function to access name of token . function name() constant returns (string _name) { return name; } // Function to access symbol of token . function symbol() constant returns (string _symbol) { return symbol; } // Function to access decimals of token . function decimals() constant returns (uint8 _decimals) { return decimals; } // Function to access total supply of tokens . function totalSupply() constant returns (uint256 _totalSupply) { return totalSupply; } // Function that is called when a user or another contract wants to transfer funds . function transfer(address _to, uint _value, bytes _data) returns (bool success) { if(isContract(_to)) { return transferToContract(_to, _value, _data); } else { return transferToAddress(_to, _value, _data); } } // Standard function transfer similar to ERC20 transfer with no _data . // Added due to backwards compatibility reasons . function transfer(address _to, uint _value) returns (bool success) { //standard function transfer similar to ERC20 transfer with no _data //added due to backwards compatibility reasons bytes memory empty; if(isContract(_to)) { return transferToContract(_to, _value, empty); } else { return transferToAddress(_to, _value, empty); } } //assemble the given address bytecode. If bytecode exists then the _addr is a contract. function isContract(address _addr) private returns (bool is_contract) { uint length; assembly { //retrieve the size of the code on target address, this needs assembly length := extcodesize(_addr) } if(length>0) { return true; } else { return false; } } //function that is called when transaction target is an address function transferToAddress(address _to, uint _value, bytes _data) private returns (bool success) { if (balanceOf(msg.sender) < _value) revert(); balances[msg.sender] = balanceOf(msg.sender).sub(_value); balances[_to] = balanceOf(_to).add(_value); Transfer(msg.sender, _to, _value); ERC223Transfer(msg.sender, _to, _value, _data); return true; } //function that is called when transaction target is a contract function transferToContract(address _to, uint _value, bytes _data) private returns (bool success) { if (balanceOf(msg.sender) < _value) revert(); balances[msg.sender] = balanceOf(msg.sender).sub(_value); balances[_to] = balanceOf(_to).add(_value); ContractReceiver reciever = ContractReceiver(_to); reciever.tokenFallback(msg.sender, _value, _data); Transfer(msg.sender, _to, _value); ERC223Transfer(msg.sender, _to, _value, _data); return true; } function balanceOf(address _owner) constant returns (uint balance) { return balances[_owner]; } }
totalSupply
function totalSupply() constant returns (uint256 _totalSupply) { return totalSupply; }
// Function to access total supply of tokens .
LineComment
v0.4.25+commit.59dbf8f1
bzzr://ab9f0fe42d9e16b9e57ac46a758e7fa8f126024174b2d499ea997543c325ce05
{ "func_code_index": [ 619, 715 ] }
9,099