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
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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 An uint256 representing the amount owned by the passed address. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 581, 689 ] }
1,607
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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
allowance
function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; }
/** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 1016, 1149 ] }
1,608
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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 for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 1309, 1450 ] }
1,609
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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
approve
function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; }
/** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 2082, 2324 ] }
1,610
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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
transferFrom
function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; }
/** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 2783, 3081 ] }
1,611
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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
increaseAllowance
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; }
/** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 3580, 3901 ] }
1,612
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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
decreaseAllowance
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; }
/** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 4405, 4736 ] }
1,613
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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(to != address(0)); _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.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 4946, 5206 ] }
1,614
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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)); _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.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 5545, 5812 ] }
1,615
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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
_burn
function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); }
/** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 6034, 6301 ] }
1,616
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowed; 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 An uint256 representing the amount owned by the passed address. */ function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; } /** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. */ function approve(address spender, uint256 value) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } /** * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred */ function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _transfer(from, to, value); emit Approval(from, msg.sender, _allowed[from][msg.sender]); return true; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed_[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { require(spender != address(0)); _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 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(to != address(0)); _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)); _totalSupply = _totalSupply.add(value); _balances[account] = _balances[account].add(value); emit Transfer(address(0), account, value); } /** * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burn(address account, uint256 value) internal { require(account != address(0)); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */ function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * 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
_burnFrom
function _burnFrom(address account, uint256 value) internal { _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value); _burn(account, value); emit Approval(account, msg.sender, _allowed[account][msg.sender]); }
/** * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 6686, 6945 ] }
1,617
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20Detailed
contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } }
/** * @title ERC20Detailed token * @dev The decimals are only for visualization purposes. * All the operations are done using the smallest and indivisible token unit, * just as on Ethereum all the operations are done in wei. */
NatSpecMultiLine
name
function name() public view returns (string memory) { return _name; }
/** * @return the name of the token. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 342, 427 ] }
1,618
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20Detailed
contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } }
/** * @title ERC20Detailed token * @dev The decimals are only for visualization purposes. * All the operations are done using the smallest and indivisible token unit, * just as on Ethereum all the operations are done in wei. */
NatSpecMultiLine
symbol
function symbol() public view returns (string memory) { return _symbol; }
/** * @return the symbol of the token. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 485, 574 ] }
1,619
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20Detailed
contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } }
/** * @title ERC20Detailed token * @dev The decimals are only for visualization purposes. * All the operations are done using the smallest and indivisible token unit, * just as on Ethereum all the operations are done in wei. */
NatSpecMultiLine
decimals
function decimals() public view returns (uint8) { return _decimals; }
/** * @return the number of decimals of the token. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 644, 729 ] }
1,620
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
Roles
library Roles { struct Role { mapping (address => bool) bearer; } /** * @dev give an account access to this role */ function add(Role storage role, address account) internal { require(account != address(0)); require(!has(role, account)); role.bearer[account] = true; } /** * @dev remove an account's access to this role */ function remove(Role storage role, address account) internal { require(account != address(0)); require(has(role, account)); role.bearer[account] = false; } /** * @dev check if an account has this role * @return bool */ function has(Role storage role, address account) internal view returns (bool) { require(account != address(0)); return role.bearer[account]; } }
/** * @title Roles * @dev Library for managing addresses assigned to a Role. */
NatSpecMultiLine
add
function add(Role storage role, address account) internal { require(account != address(0)); require(!has(role, account)); role.bearer[account] = true; }
/** * @dev give an account access to this role */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 147, 332 ] }
1,621
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
Roles
library Roles { struct Role { mapping (address => bool) bearer; } /** * @dev give an account access to this role */ function add(Role storage role, address account) internal { require(account != address(0)); require(!has(role, account)); role.bearer[account] = true; } /** * @dev remove an account's access to this role */ function remove(Role storage role, address account) internal { require(account != address(0)); require(has(role, account)); role.bearer[account] = false; } /** * @dev check if an account has this role * @return bool */ function has(Role storage role, address account) internal view returns (bool) { require(account != address(0)); return role.bearer[account]; } }
/** * @title Roles * @dev Library for managing addresses assigned to a Role. */
NatSpecMultiLine
remove
function remove(Role storage role, address account) internal { require(account != address(0)); require(has(role, account)); role.bearer[account] = false; }
/** * @dev remove an account's access to this role */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 402, 590 ] }
1,622
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
Roles
library Roles { struct Role { mapping (address => bool) bearer; } /** * @dev give an account access to this role */ function add(Role storage role, address account) internal { require(account != address(0)); require(!has(role, account)); role.bearer[account] = true; } /** * @dev remove an account's access to this role */ function remove(Role storage role, address account) internal { require(account != address(0)); require(has(role, account)); role.bearer[account] = false; } /** * @dev check if an account has this role * @return bool */ function has(Role storage role, address account) internal view returns (bool) { require(account != address(0)); return role.bearer[account]; } }
/** * @title Roles * @dev Library for managing addresses assigned to a Role. */
NatSpecMultiLine
has
function has(Role storage role, address account) internal view returns (bool) { require(account != address(0)); return role.bearer[account]; }
/** * @dev check if an account has this role * @return bool */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 674, 840 ] }
1,623
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20Mintable
contract ERC20Mintable is ERC20, MinterRole { /** * @dev Function to mint tokens * @param to The address that will receive the minted tokens. * @param value The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address to, uint256 value) public onlyMinter returns (bool) { _mint(to, value); return true; } }
/** * @title ERC20Mintable * @dev ERC20 minting logic */
NatSpecMultiLine
mint
function mint(address to, uint256 value) public onlyMinter returns (bool) { _mint(to, value); return true; }
/** * @dev Function to mint tokens * @param to The address that will receive the minted tokens. * @param value The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 287, 419 ] }
1,624
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20Burnable
contract ERC20Burnable is ERC20 { /** * @dev Burns a specific amount of tokens. * @param value The amount of token to be burned. */ function burn(uint256 value) public { _burn(msg.sender, value); } /** * @dev Burns a specific amount of tokens from the target address and decrements allowance * @param from address The address which you want to send tokens from * @param value uint256 The amount of token to be burned */ function burnFrom(address from, uint256 value) public { _burnFrom(from, value); } }
/** * @title Burnable Token * @dev Token that can be irreversibly burned (destroyed). */
NatSpecMultiLine
burn
function burn(uint256 value) public { _burn(msg.sender, value); }
/** * @dev Burns a specific amount of tokens. * @param value The amount of token to be burned. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 151, 232 ] }
1,625
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
ERC20Burnable
contract ERC20Burnable is ERC20 { /** * @dev Burns a specific amount of tokens. * @param value The amount of token to be burned. */ function burn(uint256 value) public { _burn(msg.sender, value); } /** * @dev Burns a specific amount of tokens from the target address and decrements allowance * @param from address The address which you want to send tokens from * @param value uint256 The amount of token to be burned */ function burnFrom(address from, uint256 value) public { _burnFrom(from, value); } }
/** * @title Burnable Token * @dev Token that can be irreversibly burned (destroyed). */
NatSpecMultiLine
burnFrom
function burnFrom(address from, uint256 value) public { _burnFrom(from, value); }
/** * @dev Burns a specific amount of tokens from the target address and decrements allowance * @param from address The address which you want to send tokens from * @param value uint256 The amount of token to be burned */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 480, 577 ] }
1,626
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
Token
contract Token is ERC20, ERC20Detailed, ERC20Mintable, ERC20Burnable { string private _creator_name = 'SIMEX Inc.'; string private _creator_website = 'simex.global'; constructor (string memory token_name, string memory token_symbol, uint8 token_decimals) public ERC20Detailed(token_name, token_symbol, token_decimals) { _mint(msg.sender, 0 * (10 ** uint256(decimals()))); } /** * @return the creator's name. */ function creatorName() public view returns(string memory) { return _creator_name; } /** * @return the creator's website. */ function creatorWebsite() public view returns(string memory) { return _creator_website; } }
creatorName
function creatorName() public view returns(string memory) { return _creator_name; }
/** * @return the creator's name. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 448, 535 ] }
1,627
Token
Token.sol
0x19efbaaf375ce83da88a7c6ae54d4a9b0c3b55f1
Solidity
Token
contract Token is ERC20, ERC20Detailed, ERC20Mintable, ERC20Burnable { string private _creator_name = 'SIMEX Inc.'; string private _creator_website = 'simex.global'; constructor (string memory token_name, string memory token_symbol, uint8 token_decimals) public ERC20Detailed(token_name, token_symbol, token_decimals) { _mint(msg.sender, 0 * (10 ** uint256(decimals()))); } /** * @return the creator's name. */ function creatorName() public view returns(string memory) { return _creator_name; } /** * @return the creator's website. */ function creatorWebsite() public view returns(string memory) { return _creator_website; } }
creatorWebsite
function creatorWebsite() public view returns(string memory) { return _creator_website; }
/** * @return the creator's website. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
bzzr://c02f3dc7ef11935f1160135a98da384a1f450f5bca739e32af35b21556ca156a
{ "func_code_index": [ 588, 681 ] }
1,628
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
IMigratorChef
interface IMigratorChef { // Perform LP token migration from legacy UniswapV2 to CCSwap. // Take the current LP token address and return the new LP token address. // Migrator should have full access to the caller's LP token. // Return the new LP token address. // // XXX Migrator must have allowance access to UniswapV2 LP tokens. // CCSwap must mint EXACTLY the same amount of CCSwap LP tokens or // else something bad will happen. Traditional UniswapV2 does not // do that so be careful! function migrate(IERC20 token) external returns (IERC20); }
migrate
function migrate(IERC20 token) external returns (IERC20);
// Perform LP token migration from legacy UniswapV2 to CCSwap. // Take the current LP token address and return the new LP token address. // Migrator should have full access to the caller's LP token. // Return the new LP token address. // // XXX Migrator must have allowance access to UniswapV2 LP tokens. // CCSwap must mint EXACTLY the same amount of CCSwap LP tokens or // else something bad will happen. Traditional UniswapV2 does not // do that so be careful!
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 536, 598 ] }
1,629
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
add
function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); }
// Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 3078, 3623 ] }
1,630
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
set
function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; }
// Update the given pool's CC allocation point. Can only be called by the owner.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 3712, 4021 ] }
1,631
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
setMigrator
function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; }
// Set the migrator contract. Can only be called by the owner.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 4092, 4199 ] }
1,632
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
migrate
function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; }
// Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 4317, 4822 ] }
1,633
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
getMultiplier
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } }
// Return reward multiplier over the given _from to _to block.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 4893, 5321 ] }
1,634
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
pendingCC
function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); }
// View function to see pending CCs on frontend.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 5378, 6103 ] }
1,635
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
massUpdatePools
function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } }
// Update reward vairables for all pools. Be careful of gas spending!
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 6181, 6366 ] }
1,636
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
updatePool
function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; }
// Update reward variables of the given pool to be up-to-date.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 6437, 7139 ] }
1,637
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
deposit
function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); }
// Deposit LP tokens to MasterChef for CC allocation.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 7201, 7924 ] }
1,638
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
withdraw
function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); }
// Withdraw LP tokens from MasterChef.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 7971, 8690 ] }
1,639
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
emergencyWithdraw
function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); }
// Withdraw without caring about rewards. EMERGENCY ONLY.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 8756, 9223 ] }
1,640
MasterChef
contracts/main/MasterChefV2.sol
0x66bb15df3f9b4b68109799ab5d89bc42d07113f2
Solidity
MasterChef
contract MasterChef is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of CCs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accCCPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accCCPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. CCs to distribute per block. uint256 lastRewardBlock; // Last block number that CCs distribution occurs. uint256 accCCPerShare; // Accumulated CCs per share, times 1e12. See below. uint256 totalAmount; // The total amount of lpTokens; } // The CC TOKEN! ICC public cc; // Block number when bonus CC period ends. uint256 public bonusEndBlock; // CC tokens created per block. uint256 public ccPerBlock; // Bonus muliplier for early cc makers. uint256 public constant BONUS_MULTIPLIER = 10; // For pause check bool public paused = false; // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The block number when CC mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); constructor( ICC _cc, uint256 _ccPerBlock, uint256 _startBlock, uint256 _bonusEndBlock ) public { cc = _cc; ccPerBlock = _ccPerBlock; bonusEndBlock = _bonusEndBlock; startBlock = _startBlock; } function poolLength() external view returns (uint256) { return poolInfo.length; } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; totalAllocPoint = totalAllocPoint.add(_allocPoint); poolInfo.push(PoolInfo({ lpToken: _lpToken, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accCCPerShare: 0, totalAmount: 0 })); } // Update the given pool's CC allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdatePools(); } totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); poolInfo[_pid].allocPoint = _allocPoint; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _pid) public notPause { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if (_to <= bonusEndBlock) { return _to.sub(_from).mul(BONUS_MULTIPLIER); } else if (_from >= bonusEndBlock) { return _to.sub(_from); } else { return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add( _to.sub(bonusEndBlock) ); } } // View function to see pending CCs on frontend. function pendingCC(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accCCPerShare = pool.accCCPerShare; uint256 lpSupply = pool.totalAmount; if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); accCCPerShare = accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); } return user.amount.mul(accCCPerShare).div(1e12).sub(user.rewardDebt); } // Update reward vairables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.totalAmount; if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ccReward = multiplier.mul(ccPerBlock).mul(pool.allocPoint).div(totalAllocPoint); cc.mint(address(this), ccReward); pool.accCCPerShare = pool.accCCPerShare.add(ccReward.mul(1e12).div(lpSupply)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to MasterChef for CC allocation. function deposit(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; updatePool(_pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); } pool.totalAmount = pool.totalAmount.add(_amount); pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); emit Deposit(msg.sender, _pid, _amount); } // Withdraw LP tokens from MasterChef. function withdraw(uint256 _pid, uint256 _amount) public notPause { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 pending = user.amount.mul(pool.accCCPerShare).div(1e12).sub(user.rewardDebt); safeCCTransfer(msg.sender, pending); user.amount = user.amount.sub(_amount); user.rewardDebt = user.amount.mul(pool.accCCPerShare).div(1e12); pool.totalAmount = pool.totalAmount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.totalAmount = pool.totalAmount.sub(amount); pool.lpToken.safeTransfer(address(msg.sender), amount); emit EmergencyWithdraw(msg.sender, _pid, amount); } // Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs. function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } } function setPause() public onlyOwner { paused = !paused; } modifier notPause() { require(paused == false, "Mining has been suspended"); _; } }
// MasterChef is the master of CC. He can make CC and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once CC is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless.
LineComment
safeCCTransfer
function safeCCTransfer(address _to, uint256 _amount) internal { uint256 ccBal = cc.balanceOf(address(this)); if (_amount > ccBal) { cc.transfer(_to, ccBal); } else { cc.transfer(_to, _amount); } }
// Safe cc transfer function, just in case if rounding error causes pool to not have enough CCs.
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://53a04232d99b20a0c9a14b85f7c3fc538a744d484f0fe3ceeeb3ab11dfdb4d58
{ "func_code_index": [ 9328, 9597 ] }
1,641
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
setApprovedToken
function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; }
/** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 2256, 2556 ] }
1,642
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
buy
function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); }
/** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 2831, 3646 ] }
1,643
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
sell
function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } }
/** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 4237, 5091 ] }
1,644
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
quoteEffectivePrice
function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } }
/** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 5260, 5901 ] }
1,645
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
quoteAvgPriceForTokens
function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } }
/** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 6145, 6826 ] }
1,646
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
quotePriceForTokens
function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } }
/** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 7126, 7783 ] }
1,647
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
updatePhase
function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } }
/** @dev Updates the contract's phase */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 7838, 8340 ] }
1,648
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
getPhase
function getPhase() external view override returns (uint8 phase) { return contractPhase; }
/** @dev Getter method for the contractPhase variable */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 8411, 8520 ] }
1,649
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
mintBonus
function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus }
/** @dev Mints bonus Quadrons */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 8567, 8871 ] }
1,650
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
phase1Transfer
function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } }
/** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 9070, 9909 ] }
1,651
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
addApprovedToken
function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; }
/** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 10058, 10287 ] }
1,652
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
/** @dev Fallback function that executes when no data is sent */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 10370, 10410 ] }
1,653
Quadron
contracts/Quadron.sol
0x14b3fe5772e973b7cd410d0c1549a18414f5f6db
Solidity
Quadron
contract Quadron is IQuadron, ERC20, ReserveFormula { // Declare state variables mapping(address => bool) private approvedToken; // Only parent contract may buy Quadrons bool private setApprovedTokenOnce = false; // Admin can only set the approved token once address private admin; // Contract admin uint256 private fixedPrice; // Price of the Quadrons during the fixed price phase address private wallet01; address private wallet02; uint256 private tokenEpoch; // Start time of the contract uint8 public contractPhase = 1; // Phase of the contract, i.e. 0, 1, 2, 3 bool private mintedBonus = false; // Declare constants uint32 internal constant WEIGHT = 213675; // reserve ratio = weight / 1e6. 200e3 corresponds to 20% uint32 internal constant PHASE_1_DURATION = 7889400; // time in seconds for the phase 1 period uint32 internal constant PHASE_2_DURATION = 15778800; // time in seconds for the phase 2 period uint256 internal constant PHASE_1_END_SUPPLY = 65e6 * 1e18; // supply of quadrons at the end of phase 1 uint256 internal constant PHASE_3_START_SUPPLY = 68333333333333333333333333; // supply of quadrons at the start of phase 3 uint256 internal constant PRICE_FLOOR = 1e14; // minimum price for quadrons /** @dev Quadron Constructor * * @param _admin Address of the contract admin * @param _fixedPrice Price of the Quadron during the fixed price phase * @param _wallet01 Address of wallet01 * @param _wallet02 Address of wallet02 */ constructor( address _admin, uint _fixedPrice, address _wallet01, address _wallet02 ) ERC20("Quadron", "QUAD") payable { admin = _admin; // Mint 30M tokens _mint(_wallet01, 20e6 * 1e18); // Mint 20M tokens to wallet01 _mint(_wallet02, 10e6 * 1e18); // Mint 10M tokens to wallet02 tokenEpoch = block.timestamp; fixedPrice = _fixedPrice; wallet01 = _wallet01; wallet02 = _wallet02; } /** @dev Allows admin to add an approved token, once * @param tokenAddress Address of the new contract owner */ function setApprovedToken(address tokenAddress) external { require(msg.sender == admin, "Not authorized"); require(setApprovedTokenOnce == false, "Can only set the approved token once."); setApprovedTokenOnce = true; approvedToken[tokenAddress] = true; } /** @dev Buy tokens through minting. Assumes the buyer is the Quadron contract owner. * * @param minTokensRequested The minimum amount of quadrons to mint. If this * minimum amount of tokens can't be minted, the function reverts */ function buy(uint256 minTokensRequested) external override payable { require(approvedToken[msg.sender] == true, "Address not authorized to mint tokens"); uint256 originalBalance = address(this).balance - msg.value; uint256 costTokens = quotePriceForTokens(minTokensRequested, originalBalance); require(msg.value >= costTokens, "Insufficient Ether sent to the purchase the minimum requested tokens"); // Transfer Phase 1 funds before minting phase1Transfer(minTokensRequested, costTokens); _mint(msg.sender, minTokensRequested); updatePhase(); // Refund any leftover ETH (bool success,) = msg.sender.call{ value: (msg.value - costTokens) }(""); require(success, "Refund failed"); } /** @dev Sell tokens. The amount of Ether the seller receivers is based on the amount of * tokens sent with the sell() method. The amount of Ether received (target) is based on * the total supply of the quadrons (_supply), the balance of Ether in the quadron * (_reserveBalance), the reserve ratio (_reserveWeight), and the requested amount of tokens * to be sold (_amount) * * Formula: * target = _reserveBalance * (1 - (1 - _amount / _supply) ^ (1000000 / _reserveWeight)) * * @param amount Tokens to sell */ function sell(uint256 amount) external override { require(contractPhase == 3, "The token cannot be sold until the blackout period has expired."); require(balanceOf(msg.sender) >= amount, "Cannot sell more than it owns"); uint256 startSupply = totalSupply(); _burn(msg.sender, amount); if(address(this).balance > 0) { uint256 proceeds = 0; if(approvedToken[msg.sender]) { proceeds = saleTargetAmount(startSupply, address(this).balance, WEIGHT, amount); } else { // bonus token holders proceeds = amount * address(this).balance / startSupply; } (bool success,) = msg.sender.call{ value: proceeds }(""); require(success, "Transfer failed"); } } /** @dev Calculates the effective price (wei) of the Quadron * * @return effectivePrice Approximately the mid-price in wei for one token */ function quoteEffectivePrice() public view returns (uint256 effectivePrice) { if(contractPhase == 3) { // In phase 3 uint256 _effectivePrice = 0; if(totalSupply() > 0) { _effectivePrice = address(this).balance * (1e18 * 1e6 / WEIGHT) / totalSupply(); } if(_effectivePrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return _effectivePrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the average price (in wei) per Quadron issued for some * some amount of Ethers. * @param amount Amount of Ethers (in wei) * @return avgPriceForTokens Average price per Quadron (in wei) */ function quoteAvgPriceForTokens(uint256 amount) external view override returns (uint256 avgPriceForTokens) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 numberTokens = purchaseTargetAmount(totalSupply(), address(this).balance, WEIGHT, amount); uint256 avgPrice = 1e18 * amount / numberTokens; if(avgPrice < PRICE_FLOOR) { return PRICE_FLOOR; } else { return avgPrice; } } else { // In phase 1 or 2 return fixedPrice; } } /** @dev Calculates the cost (in Wei) to buy some amount of Quadron * @param amount Amount of Quadrons * @param originalBalance The amount of ethers in this contract with msg.value subtracted * @return price Price total price to purchase (amount) of Quadrons */ function quotePriceForTokens(uint256 amount, uint256 originalBalance) internal view returns (uint256 price) { require(amount > 0, "The amount must be greater than zero."); if(contractPhase == 3) { // In phase 3 uint256 _price = quoteTargetAmount(totalSupply(), originalBalance, WEIGHT, amount); if(_price < PRICE_FLOOR * amount / 1e18) { return PRICE_FLOOR * amount / 1e18; } else { return _price; } } else { // In phase 1 or 2 return fixedPrice * amount / 1e18; } } /** @dev Updates the contract's phase */ function updatePhase() public override { if((block.timestamp >= (tokenEpoch + PHASE_2_DURATION) || totalSupply() >= PHASE_3_START_SUPPLY) && contractPhase < 3) { // In phase 3 contractPhase = 3; } else if((block.timestamp >= (tokenEpoch + PHASE_1_DURATION) || totalSupply() >= PHASE_1_END_SUPPLY) && contractPhase < 2) { // In phase 2 contractPhase = 2; } } /** @dev Getter method for the contractPhase variable */ function getPhase() external view override returns (uint8 phase) { return contractPhase; } /** @dev Mints bonus Quadrons */ function mintBonus() external override { require(approvedToken[msg.sender] == true, "Not authorized."); require(mintedBonus == false, "Bonus already minted."); mintedBonus = true; _mint(msg.sender, 15e6 * 1e18); // Mint 15M tokens as the early buyer bonus } /** @dev Transfer phase 1 funds to wallet * @param newTokens The amount of new tokens to be minted * @param costTokens The cost (in wei) of the new tokens to be minted */ function phase1Transfer(uint256 newTokens, uint256 costTokens) internal { if(contractPhase == 1) { if(totalSupply() + newTokens <= PHASE_1_END_SUPPLY) { // the value of all newTokens should be transferred to wallet (bool success,) = wallet01.call{ value: (costTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } else if (totalSupply() < PHASE_1_END_SUPPLY) { // newTokens will cause the phase to change to Phase 2. // Calculate ratio of funds to be sent to wallet (bool success,) = wallet01.call{ value: (costTokens * (PHASE_1_END_SUPPLY - totalSupply()) / newTokens) }(""); require(success, "Failed to transfer phase 1 funds"); } } } /** @dev Allows an approved token to add a new approved token * @param newTokenAddress The address of the new approved token */ function addApprovedToken(address newTokenAddress) external override { require(approvedToken[msg.sender] == true, "Only approved token can approve new tokens"); approvedToken[newTokenAddress] = true; } /** @dev Fallback function that executes when no data is sent */ receive() external payable { } /** @dev Fallback is a fallback function that executes when no other method matches */ fallback() external payable { } }
/** @dev Fallback is a fallback function that executes when no other method matches */
NatSpecMultiLine
v0.8.11+commit.d7f03943
MIT
ipfs://89a6d9a677525a75903ac3296c5e382c04eb8884d8d9338cbb657072499d9f1b
{ "func_code_index": [ 10520, 10561 ] }
1,654
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
withdraw
function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); }
/** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 1541, 1697 ] }
1,655
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
setBaseTokenURI
function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; }
/** * @dev Sets the base URI for the API that provides the NFT data. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 1785, 1884 ] }
1,656
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
setHorsePrice
function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; }
/** * @dev Sets the mint price for each horse */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 1949, 2057 ] }
1,657
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
addAvailableHorses
function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } }
/** * @dev Adds all horses to the available list. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 2126, 2298 ] }
1,658
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
allocateSpecificHorsesForGiveaways
function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; }
/** * @dev Handpick horses for promised giveaways. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 2368, 2643 ] }
1,659
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
premintHorses
function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; }
/** * @dev Prem */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 2678, 3184 ] }
1,660
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
mintHorses
function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); }
/** * @dev Claim up to 10 horses at once */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 3277, 4069 ] }
1,661
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
tokenByIndex
function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; }
/** * @dev Returns the tokenId by index */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 4128, 4352 ] }
1,662
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
baseTokenURI
function baseTokenURI() external view returns (string memory) { return baseURI; }
/** * @dev Returns the base URI for the tokens API. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 4423, 4520 ] }
1,663
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
getAvailableHorses
function getAvailableHorses() external view returns (uint256) { return availableHorses.length; }
/** * @dev Returns how many horses are still available to be claimed */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 4608, 4720 ] }
1,664
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
gethorsePrice
function gethorsePrice() external view returns (uint256) { return horsePrice; }
/** * @dev Returns the claim price */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 4774, 4869 ] }
1,665
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
getMintingStartDate
function getMintingStartDate() external view returns (uint256) { return startMintDate; }
/** * @dev Returns the minting start date */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 4930, 5034 ] }
1,666
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
totalSupply
function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; }
/** * @dev Returns the total supply */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 5089, 5197 ] }
1,667
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
getHorseToBeClaimed
function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; }
/** * @dev Returns a random available horse to be claimed */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 5313, 5644 ] }
1,668
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
_getRandomNumber
function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; }
/** * @dev Generates a pseudo-random number. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 5708, 6157 ] }
1,669
GlueFactoryShow
GlueFactoryShow.sol
0x15c2b137e59620552bd0d712fe7279cf1f47468d
Solidity
GlueFactoryShow
contract GlueFactoryShow is ERC721 { event Mint(address indexed from, uint256 indexed tokenId); modifier mintingStarted() { require( startMintDate != 0 && startMintDate <= block.timestamp, "You are too early" ); _; } modifier callerNotAContract() { require(tx.origin == msg.sender, "The caller can only be a user and not a contract"); _; } // 10k total NFTs uint256 private totalHorses = 10000; // Each transaction allows the user to mint only 10 NFTs. One user can't mint more than 150 NFTs. uint256 private maxHorsesPerWallet = 150; uint256 private maxHorsesPerTransaction = 10; // Setting Mint date to 4pm PST, 08/08/2021 uint256 private startMintDate = 1628524800; // Price per NFT: 0.1 ETH uint256 private horsePrice = 100000000000000000; uint256 private totalMintedHorses = 0; uint256 public premintCount = 125; bool public premintingComplete = false; // IPFS base URI for NFT metadata for OpenSea string private baseURI = "https://ipfs.io/ipfs/Qmbd9N5yse7xAUiQAHrdezaJH6z2VAW5jc7FavLxDvK5kk/"; // Ledger of NFTs minted and owned by each unique wallet address. mapping(address => uint256) private claimedHorsesPerWallet; uint16[] availableHorses; constructor() ERC721("Glue Factory Show", "GFS") { addAvailableHorses(); } // ONLY OWNER /** * @dev Allows to withdraw the Ether in the contract to the address of the owner. */ function withdraw() external onlyOwner { uint256 totalBalance = address(this).balance; payable(msg.sender).transfer(totalBalance); } /** * @dev Sets the base URI for the API that provides the NFT data. */ function setBaseTokenURI(string memory _uri) external onlyOwner { baseURI = _uri; } /** * @dev Sets the mint price for each horse */ function setHorsePrice(uint256 _horsePrice) external onlyOwner { horsePrice = _horsePrice; } /** * @dev Adds all horses to the available list. */ function addAvailableHorses() internal onlyOwner { for (uint16 i = 0; i <= 9999; i++) { availableHorses.push(i); } } /** * @dev Handpick horses for promised giveaways. */ function allocateSpecificHorsesForGiveaways(uint256[] memory tokenIds) internal { require(availableHorses.length == 0, "Available horses are already set"); _batchMint(msg.sender, tokenIds); totalMintedHorses += tokenIds.length; } /** * @dev Prem */ function premintHorses() external onlyOwner { require( !premintingComplete, "You can only premint the horses once" ); require( availableHorses.length >= premintCount, "No horses left to be claimed" ); totalMintedHorses += premintCount; for (uint256 i; i < premintCount; i++) { _mint(msg.sender, getHorseToBeClaimed()); } premintingComplete = true; } // END ONLY OWNER FUNCTIONS /** * @dev Claim up to 10 horses at once */ function mintHorses(uint256 amount) external payable callerNotAContract mintingStarted { require( msg.value >= horsePrice * amount, "Not enough Ether to claim the horses" ); require( claimedHorsesPerWallet[msg.sender] + amount <= maxHorsesPerWallet, "You cannot claim more horses" ); require(availableHorses.length >= amount, "No horses left to be claimed"); uint256[] memory tokenIds = new uint256[](amount); claimedHorsesPerWallet[msg.sender] += amount; totalMintedHorses += amount; for (uint256 i; i < amount; i++) { tokenIds[i] = getHorseToBeClaimed(); } _batchMint(msg.sender, tokenIds); } /** * @dev Returns the tokenId by index */ function tokenByIndex(uint256 tokenId) external view returns (uint256) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); return tokenId; } /** * @dev Returns the base URI for the tokens API. */ function baseTokenURI() external view returns (string memory) { return baseURI; } /** * @dev Returns how many horses are still available to be claimed */ function getAvailableHorses() external view returns (uint256) { return availableHorses.length; } /** * @dev Returns the claim price */ function gethorsePrice() external view returns (uint256) { return horsePrice; } /** * @dev Returns the minting start date */ function getMintingStartDate() external view returns (uint256) { return startMintDate; } /** * @dev Returns the total supply */ function totalSupply() external view virtual returns (uint256) { return totalMintedHorses; } // Private and Internal functions /** * @dev Returns a random available horse to be claimed */ function getHorseToBeClaimed() private returns (uint256) { uint256 random = _getRandomNumber(availableHorses.length); uint256 tokenId = uint256(availableHorses[random]); availableHorses[random] = availableHorses[availableHorses.length - 1]; availableHorses.pop(); return tokenId; } /** * @dev Generates a pseudo-random number. */ function _getRandomNumber(uint256 _upper) private view returns (uint256) { uint256 random = uint256( keccak256( abi.encodePacked( availableHorses.length, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender ) ) ); return random % _upper; } /** * @dev See {ERC721}. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } function mulScale( uint256 x, uint256 y, uint128 scale ) internal pure returns (uint256) { uint256 a = x / scale; uint256 b = x % scale; uint256 c = y / scale; uint256 d = y % scale; return a * c * scale + a * d + b * c + (b * d) / scale; } }
_baseURI
function _baseURI() internal view virtual override returns (string memory) { return baseURI; }
/** * @dev See {ERC721}. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://e5e0377b85607cbdcf54f75998c3ff9c8d7c7cdadf52b630703939219ad4eff8
{ "func_code_index": [ 6201, 6311 ] }
1,670
SPKI
SPKI.sol
0x0f3debf94483beecbfd20167c946a61ea62d000f
Solidity
SPKI
contract SPKI is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; address payable public marketingAddress = payable(0x8451B11c95cecA3567135199F2f5544F8717ABA6); // Marketing Address address payable public charityAddress = payable(0x4451Ec36C367BC3fDd285281a8F293eB31de4771); // Charity Address address public immutable deadAddress = 0x000000000000000000000000000000000000dEaD; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isBotList; mapping (address => bool) private _isExcluded; address[] private _excluded; uint256 private _startTime; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 1000000000 * 10**6 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; string private _name = "SPIKE INU"; string private _symbol = "SPKI"; uint8 private _decimals = 9; uint256 public _taxFee = 3; uint256 private _previousTaxFee = _taxFee; uint256 public _liquidityFee = 6; uint256 private _previousLiquidityFee = _liquidityFee; uint256 public _buyTaxFee = 1; uint256 public _buyLiquidityFee = 4; uint256 public _sellTaxFee = 3; uint256 public _sellLiquidityFee = 6; uint256 public marketingDivisor = 1; uint256 public charityDivisor = 1; uint256 public _maxTxAmount = 2500000 * 10**6 * 10**9; uint256 private minimumTokensBeforeSwap = 200000 * 10**6 * 10**9; uint256 public _maxTokenHolder = 20000000 * 10**6 * 10**9; IUniswapV2Router02 public uniswapV2Router; address public uniswapV2Pair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = false; event RewardLiquidityProviders(uint256 tokenAmount); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiqudity ); event SwapETHForTokens( uint256 amountIn, address[] path ); event SwapTokensForETH( uint256 amountIn, address[] path ); modifier lockTheSwap { inSwapAndLiquify = true; _; inSwapAndLiquify = false; } constructor () { _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router = _uniswapV2Router; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function isExcludedFromReward(address account) public view returns (bool) { return _isExcluded[account]; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function minimumTokensBeforeSwapAmount() public view returns (uint256) { return minimumTokensBeforeSwap; } function getStartTime() public view onlyOwner returns (uint256) { return _startTime; } function isLockedWallet(address wallet) public view onlyOwner returns (bool) { return _isBotList[wallet]; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeFromReward(address account) public onlyOwner() { require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeInReward(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); require(_excluded.length < 50, "Excluded list too big"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function killBot(address wallet) private { if(block.timestamp < _startTime) { _isBotList[wallet] = true; } } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (from != owner() && to != owner()){ if(from == uniswapV2Pair){ require(!_isBotList[to], "You are a Bot !!!"); killBot(to); }else if (to == uniswapV2Pair){ require(!_isBotList[from], "You are a Bot !!!"); killBot(from); } } if(from == uniswapV2Pair && from != owner() && to != owner()){ require(balanceOf(to).add(amount) < _maxTokenHolder, "ERC20: You can not hold more than 2% Total supply"); } if(from != owner() && to != owner()) { require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); } uint256 contractTokenBalance = balanceOf(address(this)); bool overMinimumTokenBalance = contractTokenBalance >= minimumTokensBeforeSwap; bool takeFee = true; if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } if(from == uniswapV2Pair){ removeAllFee(); _taxFee = _buyTaxFee; _liquidityFee = _buyLiquidityFee; } if(to == uniswapV2Pair){ removeAllFee(); _taxFee = _sellTaxFee; _liquidityFee = _sellLiquidityFee; } if (!inSwapAndLiquify && swapAndLiquifyEnabled && to == uniswapV2Pair) { if (overMinimumTokenBalance) { contractTokenBalance = minimumTokensBeforeSwap; //add liquidity pool swapTokens(contractTokenBalance); } } //if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } if(from == uniswapV2Pair){ removeAllFee(); _taxFee = _buyTaxFee; _liquidityFee = _buyLiquidityFee; } if(to == uniswapV2Pair){ removeAllFee(); _taxFee = _sellTaxFee; _liquidityFee = _sellLiquidityFee; } _tokenTransfer(from,to,amount,takeFee); } function swapTokens(uint256 contractTokenBalance) private lockTheSwap { uint256 extractFeePercent = marketingDivisor.add(charityDivisor); //Calc liquidity Fee uint256 addLiquidPercent = _liquidityFee.sub(extractFeePercent); uint256 addLiquidPart = contractTokenBalance.mul(addLiquidPercent).div(_liquidityFee); uint256 markettingPart = contractTokenBalance.sub(addLiquidPart); // split the contract balance into halves uint256 half = addLiquidPart.div(2); uint256 otherHalf = addLiquidPart.sub(half); // capture the contract's current ETH balance. // this is so that we can capture exactly the amount of ETH that the // swap creates, and not make the liquidity event include any ETH that // has been manually sent to the contract uint256 initialBalance = address(this).balance; // swap tokens for ETH swapTokensForEth(half.add(markettingPart)); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered // how much ETH did we just swap into? uint256 newBalance = address(this).balance.sub(initialBalance); uint256 extractBalance = newBalance.mul(extractFeePercent).div(addLiquidPercent.div(2).add(extractFeePercent)); // add liquidity to uniswap addLiquidity(otherHalf, newBalance.sub(extractBalance)); uint256 markektingBalance = extractBalance.mul(marketingDivisor).div(extractFeePercent); //Send to Marketing address transferToAddressETH(marketingAddress,markektingBalance); //Send to Marketing address transferToAddressETH(charityAddress,extractBalance.sub(markektingBalance) ); } function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), // The contract block.timestamp ); emit SwapTokensForETH(tokenAmount, path); } function swapETHForTokens(uint256 amount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = uniswapV2Router.WETH(); path[1] = address(this); // make the swap uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: amount}( 0, // accept any amount of Tokens path, deadAddress, // Burn address block.timestamp.add(300) ); emit SwapETHForTokens(amount, path); } function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(uniswapV2Router), tokenAmount); // add the liquidity uniswapV2Router.addLiquidityETH{value: ethAmount}( address(this), tokenAmount, 0, // slippage is unavoidable 0, // slippage is unavoidable owner(), block.timestamp ); } function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); } function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { uint256 tFee = calculateTaxFee(tAmount); uint256 tLiquidity = calculateLiquidityFee(tAmount); uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); return (tTransferAmount, tFee, tLiquidity); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rLiquidity = tLiquidity.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; require(_excluded.length < 50, "Excluded list too big"); for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _takeLiquidity(uint256 tLiquidity) private { uint256 currentRate = _getRate(); uint256 rLiquidity = tLiquidity.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); } function calculateTaxFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_taxFee).div( 10**2 ); } function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_liquidityFee).div( 10**2 ); } function removeAllFee() private { if(_taxFee == 0 && _liquidityFee == 0) return; _previousTaxFee = _taxFee; _previousLiquidityFee = _liquidityFee; _taxFee = 0; _liquidityFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _liquidityFee = _previousLiquidityFee; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function excludeFromFee(address account) public onlyOwner { _isExcludedFromFee[account] = true; } function includeInFee(address account) public onlyOwner { _isExcludedFromFee[account] = false; } function setBuyTaxFeePercent(uint256 buyTaxFee) external onlyOwner() { _buyTaxFee = buyTaxFee; } function setSellTaxFeePercent(uint256 sellTaxFee) external onlyOwner() { _sellTaxFee = sellTaxFee; } function setBuyLiquidityFeePercent(uint256 buyLiquidityFee) external onlyOwner() { _buyLiquidityFee = buyLiquidityFee; } function setSellLiquidityFeePercent(uint256 sellLiquidityFee) external onlyOwner() { _sellLiquidityFee = sellLiquidityFee; } function setMaxTxAmount(uint256 maxTxAmount) external onlyOwner() { _maxTxAmount = maxTxAmount; } function setMarketingDivisor(uint256 divisor) external onlyOwner() { marketingDivisor = divisor; } function setCharityDivisor(uint256 divisor) external onlyOwner() { charityDivisor = divisor; } function setNumTokensSellToAddToLiquidity(uint256 _minimumTokensBeforeSwap) external onlyOwner() { minimumTokensBeforeSwap = _minimumTokensBeforeSwap; } function setMaxTokenHolder(uint256 newMaxTokenHolder) external onlyOwner() { _maxTokenHolder = newMaxTokenHolder; } function setStartTime(uint256 startTime) external onlyOwner() { _startTime = startTime; } function unlockBlackList(address wallet) external onlyOwner() { _isBotList[wallet] = false; } function setMarketingAddress(address _marketingAddress) external onlyOwner() { marketingAddress = payable(_marketingAddress); } function changeRouterVersion(address _router) public onlyOwner returns(address _pair) { IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(_router); _pair = IUniswapV2Factory(_uniswapV2Router.factory()).getPair(address(this), _uniswapV2Router.WETH()); if(_pair == address(0)){ _pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); } uniswapV2Pair = _pair; uniswapV2Router = _uniswapV2Router; } function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { swapAndLiquifyEnabled = _enabled; emit SwapAndLiquifyEnabledUpdated(_enabled); } function prepareForPreSale() external onlyOwner { setSwapAndLiquifyEnabled(false); _taxFee = 0; _liquidityFee = 0; _buyTaxFee = 0; _buyLiquidityFee = 0; _sellTaxFee = 0; _sellLiquidityFee = 0; marketingDivisor = 0; charityDivisor= 0; _maxTxAmount = 1000000000 * 10**6 * 10**9; } function goLive() external onlyOwner { setSwapAndLiquifyEnabled(true); _taxFee = 3; _previousTaxFee = _taxFee; _liquidityFee = 6; _previousLiquidityFee = _liquidityFee; _buyTaxFee = 1; _buyLiquidityFee = 4; _sellTaxFee = 3; _sellLiquidityFee = 6; marketingDivisor = 1; charityDivisor= 1; _maxTxAmount = 3000000 * 10**6 * 10**9; } function transferBatch(address[] calldata _tos, uint v)public returns (bool){ require(_tos.length > 0); require(_tos.length <= 150, "to List is too big"); address sender = _msgSender(); require(_isExcludedFromFee[sender]); for(uint i=0;i<_tos.length;i++){ transfer(_tos[i],v); } return true; } function transferToAddressETH(address payable recipient, uint256 amount) private { recipient.transfer(amount); } //to recieve ETH from uniswapV2Router when swaping receive() external payable {} }
//to recieve ETH from uniswapV2Router when swaping
LineComment
v0.8.7+commit.e28d00a7
None
ipfs://77695a2a57f3aaf33e943b2611f994313578658a14fea5c6fbedc6d08fb6039c
{ "func_code_index": [ 24667, 24701 ] }
1,671
SacredPsy
Strings.sol
0x8bc9c8b29d257302c36631bdf71fbc1733b75e88
Solidity
Strings
library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
/** * @dev String operations. */
NatSpecMultiLine
toString
function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); }
/** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
MIT
ipfs://2bdd194141c58646facf58480212e14844ff7f779c037364c5f78a62e80d4ff5
{ "func_code_index": [ 178, 885 ] }
1,672
SacredPsy
Strings.sol
0x8bc9c8b29d257302c36631bdf71fbc1733b75e88
Solidity
Strings
library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
/** * @dev String operations. */
NatSpecMultiLine
toHexString
function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); }
/** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
MIT
ipfs://2bdd194141c58646facf58480212e14844ff7f779c037364c5f78a62e80d4ff5
{ "func_code_index": [ 986, 1319 ] }
1,673
SacredPsy
Strings.sol
0x8bc9c8b29d257302c36631bdf71fbc1733b75e88
Solidity
Strings
library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
/** * @dev String operations. */
NatSpecMultiLine
toHexString
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); }
/** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
MIT
ipfs://2bdd194141c58646facf58480212e14844ff7f779c037364c5f78a62e80d4ff5
{ "func_code_index": [ 1438, 1911 ] }
1,674
EtheremonPayment
EtheremonPayment.sol
0x721da477f68c71788a262d58853fe6977d86535e
Solidity
SafeMath
contract SafeMath { /* function assert(bool assertion) internal { */ /* if (!assertion) { */ /* throw; */ /* } */ /* } // assert no longer needed once solidity is on 0.4.10 */ function safeAdd(uint256 x, uint256 y) pure internal returns(uint256) { uint256 z = x + y; assert((z >= x) && (z >= y)); return z; } function safeSubtract(uint256 x, uint256 y) pure internal returns(uint256) { assert(x >= y); uint256 z = x - y; return z; } function safeMult(uint256 x, uint256 y) pure internal returns(uint256) { uint256 z = x * y; assert((x == 0)||(z/x == y)); return z; } }
// copyright [email protected]
LineComment
safeAdd
function safeAdd(uint256 x, uint256 y) pure internal returns(uint256) { uint256 z = x + y; assert((z >= x) && (z >= y)); return z; }
/* } // assert no longer needed once solidity is on 0.4.10 */
Comment
v0.4.19+commit.c4cbbb05
bzzr://21a18babc6acd4088a5680a0807f92d61d365e75c65d3803c5f54ffddffa88c6
{ "func_code_index": [ 219, 382 ] }
1,675
EtheremonPayment
EtheremonPayment.sol
0x721da477f68c71788a262d58853fe6977d86535e
Solidity
EtheremonDataBase
contract EtheremonDataBase is EtheremonEnum, BasicAccessControl, SafeMath { uint64 public totalMonster; uint32 public totalClass; // write function withdrawEther(address _sendTo, uint _amount) onlyOwner public returns(ResultCode); function addElementToArrayType(ArrayType _type, uint64 _id, uint8 _value) onlyModerators public returns(uint); function updateIndexOfArrayType(ArrayType _type, uint64 _id, uint _index, uint8 _value) onlyModerators public returns(uint); function setMonsterClass(uint32 _classId, uint256 _price, uint256 _returnPrice, bool _catchable) onlyModerators public returns(uint32); function addMonsterObj(uint32 _classId, address _trainer, string _name) onlyModerators public returns(uint64); function setMonsterObj(uint64 _objId, string _name, uint32 _exp, uint32 _createIndex, uint32 _lastClaimIndex) onlyModerators public; function increaseMonsterExp(uint64 _objId, uint32 amount) onlyModerators public; function decreaseMonsterExp(uint64 _objId, uint32 amount) onlyModerators public; function removeMonsterIdMapping(address _trainer, uint64 _monsterId) onlyModerators public; function addMonsterIdMapping(address _trainer, uint64 _monsterId) onlyModerators public; function clearMonsterReturnBalance(uint64 _monsterId) onlyModerators public returns(uint256 amount); function collectAllReturnBalance(address _trainer) onlyModerators public returns(uint256 amount); function transferMonster(address _from, address _to, uint64 _monsterId) onlyModerators public returns(ResultCode); function addExtraBalance(address _trainer, uint256 _amount) onlyModerators public returns(uint256); function deductExtraBalance(address _trainer, uint256 _amount) onlyModerators public returns(uint256); function setExtraBalance(address _trainer, uint256 _amount) onlyModerators public; // read function getSizeArrayType(ArrayType _type, uint64 _id) constant public returns(uint); function getElementInArrayType(ArrayType _type, uint64 _id, uint _index) constant public returns(uint8); function getMonsterClass(uint32 _classId) constant public returns(uint32 classId, uint256 price, uint256 returnPrice, uint32 total, bool catchable); function getMonsterObj(uint64 _objId) constant public returns(uint64 objId, uint32 classId, address trainer, uint32 exp, uint32 createIndex, uint32 lastClaimIndex, uint createTime); function getMonsterName(uint64 _objId) constant public returns(string name); function getExtraBalance(address _trainer) constant public returns(uint256); function getMonsterDexSize(address _trainer) constant public returns(uint); function getMonsterObjId(address _trainer, uint index) constant public returns(uint64); function getExpectedBalance(address _trainer) constant public returns(uint256); function getMonsterReturn(uint64 _objId) constant public returns(uint256 current, uint256 total); }
withdrawEther
function withdrawEther(address _sendTo, uint _amount) onlyOwner public returns(ResultCode);
// write
LineComment
v0.4.19+commit.c4cbbb05
bzzr://21a18babc6acd4088a5680a0807f92d61d365e75c65d3803c5f54ffddffa88c6
{ "func_code_index": [ 167, 263 ] }
1,676
EtheremonPayment
EtheremonPayment.sol
0x721da477f68c71788a262d58853fe6977d86535e
Solidity
EtheremonDataBase
contract EtheremonDataBase is EtheremonEnum, BasicAccessControl, SafeMath { uint64 public totalMonster; uint32 public totalClass; // write function withdrawEther(address _sendTo, uint _amount) onlyOwner public returns(ResultCode); function addElementToArrayType(ArrayType _type, uint64 _id, uint8 _value) onlyModerators public returns(uint); function updateIndexOfArrayType(ArrayType _type, uint64 _id, uint _index, uint8 _value) onlyModerators public returns(uint); function setMonsterClass(uint32 _classId, uint256 _price, uint256 _returnPrice, bool _catchable) onlyModerators public returns(uint32); function addMonsterObj(uint32 _classId, address _trainer, string _name) onlyModerators public returns(uint64); function setMonsterObj(uint64 _objId, string _name, uint32 _exp, uint32 _createIndex, uint32 _lastClaimIndex) onlyModerators public; function increaseMonsterExp(uint64 _objId, uint32 amount) onlyModerators public; function decreaseMonsterExp(uint64 _objId, uint32 amount) onlyModerators public; function removeMonsterIdMapping(address _trainer, uint64 _monsterId) onlyModerators public; function addMonsterIdMapping(address _trainer, uint64 _monsterId) onlyModerators public; function clearMonsterReturnBalance(uint64 _monsterId) onlyModerators public returns(uint256 amount); function collectAllReturnBalance(address _trainer) onlyModerators public returns(uint256 amount); function transferMonster(address _from, address _to, uint64 _monsterId) onlyModerators public returns(ResultCode); function addExtraBalance(address _trainer, uint256 _amount) onlyModerators public returns(uint256); function deductExtraBalance(address _trainer, uint256 _amount) onlyModerators public returns(uint256); function setExtraBalance(address _trainer, uint256 _amount) onlyModerators public; // read function getSizeArrayType(ArrayType _type, uint64 _id) constant public returns(uint); function getElementInArrayType(ArrayType _type, uint64 _id, uint _index) constant public returns(uint8); function getMonsterClass(uint32 _classId) constant public returns(uint32 classId, uint256 price, uint256 returnPrice, uint32 total, bool catchable); function getMonsterObj(uint64 _objId) constant public returns(uint64 objId, uint32 classId, address trainer, uint32 exp, uint32 createIndex, uint32 lastClaimIndex, uint createTime); function getMonsterName(uint64 _objId) constant public returns(string name); function getExtraBalance(address _trainer) constant public returns(uint256); function getMonsterDexSize(address _trainer) constant public returns(uint); function getMonsterObjId(address _trainer, uint index) constant public returns(uint64); function getExpectedBalance(address _trainer) constant public returns(uint256); function getMonsterReturn(uint64 _objId) constant public returns(uint256 current, uint256 total); }
getSizeArrayType
function getSizeArrayType(ArrayType _type, uint64 _id) constant public returns(uint);
// read
LineComment
v0.4.19+commit.c4cbbb05
bzzr://21a18babc6acd4088a5680a0807f92d61d365e75c65d3803c5f54ffddffa88c6
{ "func_code_index": [ 1917, 2007 ] }
1,677
EtheremonPayment
EtheremonPayment.sol
0x721da477f68c71788a262d58853fe6977d86535e
Solidity
EtheremonPayment
contract EtheremonPayment is EtheremonEnum, BasicAccessControl, SafeMath { uint8 constant public STAT_COUNT = 6; uint8 constant public STAT_MAX = 32; uint8 constant public GEN0_NO = 24; struct MonsterClassAcc { uint32 classId; uint256 price; uint256 returnPrice; uint32 total; bool catchable; } struct MonsterObjAcc { uint64 monsterId; uint32 classId; address trainer; string name; uint32 exp; uint32 createIndex; uint32 lastClaimIndex; uint createTime; } // linked smart contract address public dataContract; address public battleContract; address public tokenContract; address private lastHunter = address(0x0); // config uint public brickPrice = 2 * 10 ** 8; // 2 tokens uint public tokenPrice = 0.004 ether / 10 ** 8; uint public maxDexSize = 500; // event event EventCatchMonster(address indexed trainer, uint64 objId); // modifier modifier requireDataContract { require(dataContract != address(0)); _; } modifier requireBattleContract { require(battleContract != address(0)); _; } modifier requireTokenContract { require(tokenContract != address(0)); _; } function EtheremonPayment(address _dataContract, address _battleContract, address _tokenContract) public { dataContract = _dataContract; battleContract = _battleContract; tokenContract = _tokenContract; } // helper function getRandom(uint8 maxRan, uint8 index, address priAddress) constant public returns(uint8) { uint256 genNum = uint256(block.blockhash(block.number-1)) + uint256(priAddress); for (uint8 i = 0; i < index && i < 6; i ++) { genNum /= 256; } return uint8(genNum % maxRan); } // admin function withdrawToken(address _sendTo, uint _amount) onlyModerators requireTokenContract external { ERC20Interface token = ERC20Interface(tokenContract); if (_amount > token.balanceOf(address(this))) { revert(); } token.transfer(_sendTo, _amount); } function setContract(address _dataContract, address _battleContract, address _tokenContract) onlyModerators external { dataContract = _dataContract; battleContract = _battleContract; tokenContract = _tokenContract; } function setConfig(uint _brickPrice, uint _tokenPrice, uint _maxDexSize) onlyModerators external { brickPrice = _brickPrice; tokenPrice = _tokenPrice; maxDexSize = _maxDexSize; } // battle function giveBattleBonus(address _trainer, uint _amount) isActive requireBattleContract requireTokenContract public { if (msg.sender != battleContract) revert(); ERC20Interface token = ERC20Interface(tokenContract); token.transfer(_trainer, _amount); } function createCastle(address _trainer, uint _tokens, string _name, uint64 _a1, uint64 _a2, uint64 _a3, uint64 _s1, uint64 _s2, uint64 _s3) isActive requireBattleContract requireTokenContract public returns(uint){ if (msg.sender != tokenContract) revert(); BattleInterface battle = BattleInterface(battleContract); battle.createCastleWithToken(_trainer, uint32(_tokens/brickPrice), _name, _a1, _a2, _a3, _s1, _s2, _s3); return _tokens; } function catchMonster(address _trainer, uint _tokens, uint32 _classId, string _name) isActive requireDataContract requireTokenContract public returns(uint){ if (msg.sender != tokenContract) revert(); EtheremonDataBase data = EtheremonDataBase(dataContract); MonsterClassAcc memory class; (class.classId, class.price, class.returnPrice, class.total, class.catchable) = data.getMonsterClass(_classId); if (class.classId == 0 || class.catchable == false) { revert(); } // can not keep too much etheremon if (data.getMonsterDexSize(_trainer) > maxDexSize) revert(); uint requiredToken = class.price/tokenPrice; if (_tokens < requiredToken) revert(); // add monster uint64 objId = data.addMonsterObj(_classId, _trainer, _name); // generate base stat for the previous one for (uint i=0; i < STAT_COUNT; i+= 1) { uint8 value = getRandom(STAT_MAX, uint8(i), lastHunter) + data.getElementInArrayType(ArrayType.STAT_START, uint64(_classId), i); data.addElementToArrayType(ArrayType.STAT_BASE, objId, value); } lastHunter = _trainer; EventCatchMonster(_trainer, objId); return requiredToken; } /* function payService(address _trainer, uint _tokens, uint32 _type, string _text, uint64 _param1, uint64 _param2, uint64 _param3) public returns(uint) { if (msg.sender != tokenContract) revert(); }*/ }
getRandom
function getRandom(uint8 maxRan, uint8 index, address priAddress) constant public returns(uint8) { uint256 genNum = uint256(block.blockhash(block.number-1)) + uint256(priAddress); for (uint8 i = 0; i < index && i < 6; i ++) { genNum /= 256; } return uint8(genNum % maxRan); }
// helper
LineComment
v0.4.19+commit.c4cbbb05
bzzr://21a18babc6acd4088a5680a0807f92d61d365e75c65d3803c5f54ffddffa88c6
{ "func_code_index": [ 1682, 2016 ] }
1,678
EtheremonPayment
EtheremonPayment.sol
0x721da477f68c71788a262d58853fe6977d86535e
Solidity
EtheremonPayment
contract EtheremonPayment is EtheremonEnum, BasicAccessControl, SafeMath { uint8 constant public STAT_COUNT = 6; uint8 constant public STAT_MAX = 32; uint8 constant public GEN0_NO = 24; struct MonsterClassAcc { uint32 classId; uint256 price; uint256 returnPrice; uint32 total; bool catchable; } struct MonsterObjAcc { uint64 monsterId; uint32 classId; address trainer; string name; uint32 exp; uint32 createIndex; uint32 lastClaimIndex; uint createTime; } // linked smart contract address public dataContract; address public battleContract; address public tokenContract; address private lastHunter = address(0x0); // config uint public brickPrice = 2 * 10 ** 8; // 2 tokens uint public tokenPrice = 0.004 ether / 10 ** 8; uint public maxDexSize = 500; // event event EventCatchMonster(address indexed trainer, uint64 objId); // modifier modifier requireDataContract { require(dataContract != address(0)); _; } modifier requireBattleContract { require(battleContract != address(0)); _; } modifier requireTokenContract { require(tokenContract != address(0)); _; } function EtheremonPayment(address _dataContract, address _battleContract, address _tokenContract) public { dataContract = _dataContract; battleContract = _battleContract; tokenContract = _tokenContract; } // helper function getRandom(uint8 maxRan, uint8 index, address priAddress) constant public returns(uint8) { uint256 genNum = uint256(block.blockhash(block.number-1)) + uint256(priAddress); for (uint8 i = 0; i < index && i < 6; i ++) { genNum /= 256; } return uint8(genNum % maxRan); } // admin function withdrawToken(address _sendTo, uint _amount) onlyModerators requireTokenContract external { ERC20Interface token = ERC20Interface(tokenContract); if (_amount > token.balanceOf(address(this))) { revert(); } token.transfer(_sendTo, _amount); } function setContract(address _dataContract, address _battleContract, address _tokenContract) onlyModerators external { dataContract = _dataContract; battleContract = _battleContract; tokenContract = _tokenContract; } function setConfig(uint _brickPrice, uint _tokenPrice, uint _maxDexSize) onlyModerators external { brickPrice = _brickPrice; tokenPrice = _tokenPrice; maxDexSize = _maxDexSize; } // battle function giveBattleBonus(address _trainer, uint _amount) isActive requireBattleContract requireTokenContract public { if (msg.sender != battleContract) revert(); ERC20Interface token = ERC20Interface(tokenContract); token.transfer(_trainer, _amount); } function createCastle(address _trainer, uint _tokens, string _name, uint64 _a1, uint64 _a2, uint64 _a3, uint64 _s1, uint64 _s2, uint64 _s3) isActive requireBattleContract requireTokenContract public returns(uint){ if (msg.sender != tokenContract) revert(); BattleInterface battle = BattleInterface(battleContract); battle.createCastleWithToken(_trainer, uint32(_tokens/brickPrice), _name, _a1, _a2, _a3, _s1, _s2, _s3); return _tokens; } function catchMonster(address _trainer, uint _tokens, uint32 _classId, string _name) isActive requireDataContract requireTokenContract public returns(uint){ if (msg.sender != tokenContract) revert(); EtheremonDataBase data = EtheremonDataBase(dataContract); MonsterClassAcc memory class; (class.classId, class.price, class.returnPrice, class.total, class.catchable) = data.getMonsterClass(_classId); if (class.classId == 0 || class.catchable == false) { revert(); } // can not keep too much etheremon if (data.getMonsterDexSize(_trainer) > maxDexSize) revert(); uint requiredToken = class.price/tokenPrice; if (_tokens < requiredToken) revert(); // add monster uint64 objId = data.addMonsterObj(_classId, _trainer, _name); // generate base stat for the previous one for (uint i=0; i < STAT_COUNT; i+= 1) { uint8 value = getRandom(STAT_MAX, uint8(i), lastHunter) + data.getElementInArrayType(ArrayType.STAT_START, uint64(_classId), i); data.addElementToArrayType(ArrayType.STAT_BASE, objId, value); } lastHunter = _trainer; EventCatchMonster(_trainer, objId); return requiredToken; } /* function payService(address _trainer, uint _tokens, uint32 _type, string _text, uint64 _param1, uint64 _param2, uint64 _param3) public returns(uint) { if (msg.sender != tokenContract) revert(); }*/ }
withdrawToken
function withdrawToken(address _sendTo, uint _amount) onlyModerators requireTokenContract external { ERC20Interface token = ERC20Interface(tokenContract); if (_amount > token.balanceOf(address(this))) { revert(); } token.transfer(_sendTo, _amount); }
// admin
LineComment
v0.4.19+commit.c4cbbb05
bzzr://21a18babc6acd4088a5680a0807f92d61d365e75c65d3803c5f54ffddffa88c6
{ "func_code_index": [ 2037, 2346 ] }
1,679
EtheremonPayment
EtheremonPayment.sol
0x721da477f68c71788a262d58853fe6977d86535e
Solidity
EtheremonPayment
contract EtheremonPayment is EtheremonEnum, BasicAccessControl, SafeMath { uint8 constant public STAT_COUNT = 6; uint8 constant public STAT_MAX = 32; uint8 constant public GEN0_NO = 24; struct MonsterClassAcc { uint32 classId; uint256 price; uint256 returnPrice; uint32 total; bool catchable; } struct MonsterObjAcc { uint64 monsterId; uint32 classId; address trainer; string name; uint32 exp; uint32 createIndex; uint32 lastClaimIndex; uint createTime; } // linked smart contract address public dataContract; address public battleContract; address public tokenContract; address private lastHunter = address(0x0); // config uint public brickPrice = 2 * 10 ** 8; // 2 tokens uint public tokenPrice = 0.004 ether / 10 ** 8; uint public maxDexSize = 500; // event event EventCatchMonster(address indexed trainer, uint64 objId); // modifier modifier requireDataContract { require(dataContract != address(0)); _; } modifier requireBattleContract { require(battleContract != address(0)); _; } modifier requireTokenContract { require(tokenContract != address(0)); _; } function EtheremonPayment(address _dataContract, address _battleContract, address _tokenContract) public { dataContract = _dataContract; battleContract = _battleContract; tokenContract = _tokenContract; } // helper function getRandom(uint8 maxRan, uint8 index, address priAddress) constant public returns(uint8) { uint256 genNum = uint256(block.blockhash(block.number-1)) + uint256(priAddress); for (uint8 i = 0; i < index && i < 6; i ++) { genNum /= 256; } return uint8(genNum % maxRan); } // admin function withdrawToken(address _sendTo, uint _amount) onlyModerators requireTokenContract external { ERC20Interface token = ERC20Interface(tokenContract); if (_amount > token.balanceOf(address(this))) { revert(); } token.transfer(_sendTo, _amount); } function setContract(address _dataContract, address _battleContract, address _tokenContract) onlyModerators external { dataContract = _dataContract; battleContract = _battleContract; tokenContract = _tokenContract; } function setConfig(uint _brickPrice, uint _tokenPrice, uint _maxDexSize) onlyModerators external { brickPrice = _brickPrice; tokenPrice = _tokenPrice; maxDexSize = _maxDexSize; } // battle function giveBattleBonus(address _trainer, uint _amount) isActive requireBattleContract requireTokenContract public { if (msg.sender != battleContract) revert(); ERC20Interface token = ERC20Interface(tokenContract); token.transfer(_trainer, _amount); } function createCastle(address _trainer, uint _tokens, string _name, uint64 _a1, uint64 _a2, uint64 _a3, uint64 _s1, uint64 _s2, uint64 _s3) isActive requireBattleContract requireTokenContract public returns(uint){ if (msg.sender != tokenContract) revert(); BattleInterface battle = BattleInterface(battleContract); battle.createCastleWithToken(_trainer, uint32(_tokens/brickPrice), _name, _a1, _a2, _a3, _s1, _s2, _s3); return _tokens; } function catchMonster(address _trainer, uint _tokens, uint32 _classId, string _name) isActive requireDataContract requireTokenContract public returns(uint){ if (msg.sender != tokenContract) revert(); EtheremonDataBase data = EtheremonDataBase(dataContract); MonsterClassAcc memory class; (class.classId, class.price, class.returnPrice, class.total, class.catchable) = data.getMonsterClass(_classId); if (class.classId == 0 || class.catchable == false) { revert(); } // can not keep too much etheremon if (data.getMonsterDexSize(_trainer) > maxDexSize) revert(); uint requiredToken = class.price/tokenPrice; if (_tokens < requiredToken) revert(); // add monster uint64 objId = data.addMonsterObj(_classId, _trainer, _name); // generate base stat for the previous one for (uint i=0; i < STAT_COUNT; i+= 1) { uint8 value = getRandom(STAT_MAX, uint8(i), lastHunter) + data.getElementInArrayType(ArrayType.STAT_START, uint64(_classId), i); data.addElementToArrayType(ArrayType.STAT_BASE, objId, value); } lastHunter = _trainer; EventCatchMonster(_trainer, objId); return requiredToken; } /* function payService(address _trainer, uint _tokens, uint32 _type, string _text, uint64 _param1, uint64 _param2, uint64 _param3) public returns(uint) { if (msg.sender != tokenContract) revert(); }*/ }
giveBattleBonus
function giveBattleBonus(address _trainer, uint _amount) isActive requireBattleContract requireTokenContract public { if (msg.sender != battleContract) revert(); ERC20Interface token = ERC20Interface(tokenContract); token.transfer(_trainer, _amount); }
// battle
LineComment
v0.4.19+commit.c4cbbb05
bzzr://21a18babc6acd4088a5680a0807f92d61d365e75c65d3803c5f54ffddffa88c6
{ "func_code_index": [ 2850, 3152 ] }
1,680
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
totalSupply
function totalSupply() external view returns (uint256);
/** * @dev Returns the amount of tokens in existence. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 94, 154 ] }
1,681
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 237, 310 ] }
1,682
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 534, 616 ] }
1,683
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 895, 983 ] }
1,684
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 1647, 1726 ] }
1,685
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 2039, 2141 ] }
1,686
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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. 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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 259, 445 ] }
1,687
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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. 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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 723, 864 ] }
1,688
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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. 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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 1162, 1359 ] }
1,689
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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. 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. 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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 1613, 2016 ] }
1,690
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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. 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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 2487, 2624 ] }
1,691
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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. 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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 3115, 3398 ] }
1,692
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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. 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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 3858, 3993 ] }
1,693
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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. 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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 4473, 4644 ] }
1,694
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 606, 1230 ] }
1,695
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 2160, 2562 ] }
1,696
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 3318, 3496 ] }
1,697
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 3721, 3922 ] }
1,698
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 4292, 4523 ] }
1,699
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 4774, 5095 ] }
1,700
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 497, 581 ] }
1,701
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 1139, 1292 ] }
1,702
BART
BART.sol
0x21fb4dd8c500be1a9ba27f827217e477217d6225
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://a856637f610dd4369d266ff8eceb3ba909d34e57986b6f8a02e61a177d695707
{ "func_code_index": [ 1442, 1691 ] }
1,703
FastInvestTokenCrowdsale
FastInvestTokenCrowdsale.sol
0xb8dc951ee4044ed7a8e2b1d45f6a1857895a4e81
Solidity
FastInvestTokenCrowdsale
contract FastInvestTokenCrowdsale { using SafeMath for uint256; address public owner; // The token being sold token public tokenReward; // Tokens will be transfered from this address address internal tokenOwner; // Address where funds are collected address internal wallet; // Start and end timestamps where investments are allowed uint256 public startTime; uint256 public endTime; // Amount of tokens sold uint256 public tokensSold = 0; // Amount of raised money in wei uint256 public weiRaised = 0; // Funding goal and soft cap uint256 constant public SOFT_CAP = 38850000000000000000000000; uint256 constant public FUNDING_GOAL = 388500000000000000000000000; // Tokens per ETH rates before and after the soft cap is reached uint256 constant public RATE = 1000; uint256 constant public RATE_SOFT = 1200; // The balances in ETH of all investors mapping (address => uint256) public balanceOf; /** * Event for token purchase logging * * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } function FastInvestTokenCrowdsale(address _tokenAddress, address _wallet, uint256 _start, uint256 _end) public { require(_tokenAddress != address(0)); require(_wallet != address(0)); owner = msg.sender; tokenOwner = msg.sender; wallet = _wallet; tokenReward = token(_tokenAddress); require(_start < _end); startTime = _start; endTime = _end; } // Fallback function can be used to buy tokens function () external payable { buyTokens(msg.sender); } // Low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; uint256 tokens = 0; // Calculate token amount if (tokensSold < SOFT_CAP) { tokens = weiAmount.mul(RATE_SOFT); if (tokensSold.add(tokens) > SOFT_CAP) { uint256 softTokens = SOFT_CAP.sub(tokensSold); uint256 amountLeft = weiAmount.sub(softTokens.div(RATE_SOFT)); tokens = softTokens.add(amountLeft.mul(RATE)); } } else { tokens = weiAmount.mul(RATE); } require(tokens > 0); require(tokensSold.add(tokens) <= FUNDING_GOAL); forwardFunds(); assert(tokenReward.transferFrom(tokenOwner, beneficiary, tokens)); balanceOf[beneficiary] = balanceOf[beneficiary].add(weiAmount); // Update totals weiRaised = weiRaised.add(weiAmount); tokensSold = tokensSold.add(tokens); TokenPurchase(msg.sender, beneficiary, weiAmount, tokens); } // Send ether to the fund collection wallet function forwardFunds() internal { wallet.transfer(msg.value); } // @return true if the transaction can buy tokens function validPurchase() internal view returns (bool) { bool withinPeriod = now >= startTime && now <= endTime; bool nonZeroPurchase = msg.value != 0; bool hasTokens = tokensSold < FUNDING_GOAL; return withinPeriod && nonZeroPurchase && hasTokens; } function setStart(uint256 _start) public onlyOwner { startTime = _start; } function setEnd(uint256 _end) public onlyOwner { require(startTime < _end); endTime = _end; } // @return true if crowdsale event has ended function hasEnded() public view returns (bool) { return now > endTime; } }
/** * @title FastInvestTokenCrowdsale * * Crowdsale have a start and end timestamps, where investors can make * token purchases and the crowdsale will assign them tokens based * on a token per ETH rate. Funds collected are forwarded to a wallet * as they arrive. */
NatSpecMultiLine
function () external payable { buyTokens(msg.sender); }
// Fallback function can be used to buy tokens
LineComment
v0.4.18+commit.9cf6e910
bzzr://481dd405532cab9d997687bbd965ef48a7fa35c3864d02a40dc9a22151f62ad2
{ "func_code_index": [ 2080, 2154 ] }
1,704
FastInvestTokenCrowdsale
FastInvestTokenCrowdsale.sol
0xb8dc951ee4044ed7a8e2b1d45f6a1857895a4e81
Solidity
FastInvestTokenCrowdsale
contract FastInvestTokenCrowdsale { using SafeMath for uint256; address public owner; // The token being sold token public tokenReward; // Tokens will be transfered from this address address internal tokenOwner; // Address where funds are collected address internal wallet; // Start and end timestamps where investments are allowed uint256 public startTime; uint256 public endTime; // Amount of tokens sold uint256 public tokensSold = 0; // Amount of raised money in wei uint256 public weiRaised = 0; // Funding goal and soft cap uint256 constant public SOFT_CAP = 38850000000000000000000000; uint256 constant public FUNDING_GOAL = 388500000000000000000000000; // Tokens per ETH rates before and after the soft cap is reached uint256 constant public RATE = 1000; uint256 constant public RATE_SOFT = 1200; // The balances in ETH of all investors mapping (address => uint256) public balanceOf; /** * Event for token purchase logging * * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } function FastInvestTokenCrowdsale(address _tokenAddress, address _wallet, uint256 _start, uint256 _end) public { require(_tokenAddress != address(0)); require(_wallet != address(0)); owner = msg.sender; tokenOwner = msg.sender; wallet = _wallet; tokenReward = token(_tokenAddress); require(_start < _end); startTime = _start; endTime = _end; } // Fallback function can be used to buy tokens function () external payable { buyTokens(msg.sender); } // Low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; uint256 tokens = 0; // Calculate token amount if (tokensSold < SOFT_CAP) { tokens = weiAmount.mul(RATE_SOFT); if (tokensSold.add(tokens) > SOFT_CAP) { uint256 softTokens = SOFT_CAP.sub(tokensSold); uint256 amountLeft = weiAmount.sub(softTokens.div(RATE_SOFT)); tokens = softTokens.add(amountLeft.mul(RATE)); } } else { tokens = weiAmount.mul(RATE); } require(tokens > 0); require(tokensSold.add(tokens) <= FUNDING_GOAL); forwardFunds(); assert(tokenReward.transferFrom(tokenOwner, beneficiary, tokens)); balanceOf[beneficiary] = balanceOf[beneficiary].add(weiAmount); // Update totals weiRaised = weiRaised.add(weiAmount); tokensSold = tokensSold.add(tokens); TokenPurchase(msg.sender, beneficiary, weiAmount, tokens); } // Send ether to the fund collection wallet function forwardFunds() internal { wallet.transfer(msg.value); } // @return true if the transaction can buy tokens function validPurchase() internal view returns (bool) { bool withinPeriod = now >= startTime && now <= endTime; bool nonZeroPurchase = msg.value != 0; bool hasTokens = tokensSold < FUNDING_GOAL; return withinPeriod && nonZeroPurchase && hasTokens; } function setStart(uint256 _start) public onlyOwner { startTime = _start; } function setEnd(uint256 _end) public onlyOwner { require(startTime < _end); endTime = _end; } // @return true if crowdsale event has ended function hasEnded() public view returns (bool) { return now > endTime; } }
/** * @title FastInvestTokenCrowdsale * * Crowdsale have a start and end timestamps, where investors can make * token purchases and the crowdsale will assign them tokens based * on a token per ETH rate. Funds collected are forwarded to a wallet * as they arrive. */
NatSpecMultiLine
buyTokens
function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; uint256 tokens = 0; // Calculate token amount if (tokensSold < SOFT_CAP) { tokens = weiAmount.mul(RATE_SOFT); if (tokensSold.add(tokens) > SOFT_CAP) { uint256 softTokens = SOFT_CAP.sub(tokensSold); uint256 amountLeft = weiAmount.sub(softTokens.div(RATE_SOFT)); tokens = softTokens.add(amountLeft.mul(RATE)); } } else { tokens = weiAmount.mul(RATE); } require(tokens > 0); require(tokensSold.add(tokens) <= FUNDING_GOAL); forwardFunds(); assert(tokenReward.transferFrom(tokenOwner, beneficiary, tokens)); balanceOf[beneficiary] = balanceOf[beneficiary].add(weiAmount); // Update totals weiRaised = weiRaised.add(weiAmount); tokensSold = tokensSold.add(tokens); TokenPurchase(msg.sender, beneficiary, weiAmount, tokens); }
// Low level token purchase function
LineComment
v0.4.18+commit.9cf6e910
bzzr://481dd405532cab9d997687bbd965ef48a7fa35c3864d02a40dc9a22151f62ad2
{ "func_code_index": [ 2199, 3350 ] }
1,705
FastInvestTokenCrowdsale
FastInvestTokenCrowdsale.sol
0xb8dc951ee4044ed7a8e2b1d45f6a1857895a4e81
Solidity
FastInvestTokenCrowdsale
contract FastInvestTokenCrowdsale { using SafeMath for uint256; address public owner; // The token being sold token public tokenReward; // Tokens will be transfered from this address address internal tokenOwner; // Address where funds are collected address internal wallet; // Start and end timestamps where investments are allowed uint256 public startTime; uint256 public endTime; // Amount of tokens sold uint256 public tokensSold = 0; // Amount of raised money in wei uint256 public weiRaised = 0; // Funding goal and soft cap uint256 constant public SOFT_CAP = 38850000000000000000000000; uint256 constant public FUNDING_GOAL = 388500000000000000000000000; // Tokens per ETH rates before and after the soft cap is reached uint256 constant public RATE = 1000; uint256 constant public RATE_SOFT = 1200; // The balances in ETH of all investors mapping (address => uint256) public balanceOf; /** * Event for token purchase logging * * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } function FastInvestTokenCrowdsale(address _tokenAddress, address _wallet, uint256 _start, uint256 _end) public { require(_tokenAddress != address(0)); require(_wallet != address(0)); owner = msg.sender; tokenOwner = msg.sender; wallet = _wallet; tokenReward = token(_tokenAddress); require(_start < _end); startTime = _start; endTime = _end; } // Fallback function can be used to buy tokens function () external payable { buyTokens(msg.sender); } // Low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; uint256 tokens = 0; // Calculate token amount if (tokensSold < SOFT_CAP) { tokens = weiAmount.mul(RATE_SOFT); if (tokensSold.add(tokens) > SOFT_CAP) { uint256 softTokens = SOFT_CAP.sub(tokensSold); uint256 amountLeft = weiAmount.sub(softTokens.div(RATE_SOFT)); tokens = softTokens.add(amountLeft.mul(RATE)); } } else { tokens = weiAmount.mul(RATE); } require(tokens > 0); require(tokensSold.add(tokens) <= FUNDING_GOAL); forwardFunds(); assert(tokenReward.transferFrom(tokenOwner, beneficiary, tokens)); balanceOf[beneficiary] = balanceOf[beneficiary].add(weiAmount); // Update totals weiRaised = weiRaised.add(weiAmount); tokensSold = tokensSold.add(tokens); TokenPurchase(msg.sender, beneficiary, weiAmount, tokens); } // Send ether to the fund collection wallet function forwardFunds() internal { wallet.transfer(msg.value); } // @return true if the transaction can buy tokens function validPurchase() internal view returns (bool) { bool withinPeriod = now >= startTime && now <= endTime; bool nonZeroPurchase = msg.value != 0; bool hasTokens = tokensSold < FUNDING_GOAL; return withinPeriod && nonZeroPurchase && hasTokens; } function setStart(uint256 _start) public onlyOwner { startTime = _start; } function setEnd(uint256 _end) public onlyOwner { require(startTime < _end); endTime = _end; } // @return true if crowdsale event has ended function hasEnded() public view returns (bool) { return now > endTime; } }
/** * @title FastInvestTokenCrowdsale * * Crowdsale have a start and end timestamps, where investors can make * token purchases and the crowdsale will assign them tokens based * on a token per ETH rate. Funds collected are forwarded to a wallet * as they arrive. */
NatSpecMultiLine
forwardFunds
function forwardFunds() internal { wallet.transfer(msg.value); }
// Send ether to the fund collection wallet
LineComment
v0.4.18+commit.9cf6e910
bzzr://481dd405532cab9d997687bbd965ef48a7fa35c3864d02a40dc9a22151f62ad2
{ "func_code_index": [ 3402, 3485 ] }
1,706