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
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 534, 616 ] }
7,907
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 895, 983 ] }
7,908
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 1647, 1726 ] }
7,909
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 2039, 2141 ] }
7,910
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
claim
function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); }
/** * @notice allows wallet to claim OHM * @param _amount uint */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 2326, 2439 ] }
7,911
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
stake
function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } }
/** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 2610, 2917 ] }
7,912
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
_claim
function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } }
/** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 3037, 3896 ] }
7,913
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
pushWalletChange
function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; }
/** * @notice allows address to push terms to new address * @param _newAddress address */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 4014, 4190 ] }
7,914
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
pullWalletChange
function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; }
/** * @notice allows new address to pull terms * @param _oldAddress address */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 4301, 4610 ] }
7,915
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
redeemableFor
function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); }
/** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 4808, 5035 ] }
7,916
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
claimed
function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); }
/** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 5175, 5350 ] }
7,917
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
circulatingSupply
function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); }
/** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 5504, 5638 ] }
7,918
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
setTerms
function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); }
/** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 5964, 6697 ] }
7,919
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
pushOwnership
function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; }
/** * @notice push ownership of contract * @param _newOwner address */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 6796, 7002 ] }
7,920
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
pullOwnership
function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); }
/** * @notice pull ownership of contract */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 7071, 7221 ] }
7,921
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
renounceOwnership
function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); }
/** * @notice renounce ownership of contract (no owner) */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 7301, 7482 ] }
7,922
GenesisClaim
GenesisClaim.sol
0xeaaa9d97be33a764031eddeba1cb6cb385350ca3
Solidity
GenesisClaim
contract GenesisClaim { /* ========== DEPENDENCIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STRUCTS ========== */ struct Term { uint percent; // 4 decimals ( 5000 = 0.5% ) uint claimed; // static number uint wClaimed; // rebase-tracking number uint max; // maximum nominal OHM amount can claim } /* ========== STATE VARIABLES ========== */ address owner; // can set terms address newOwner; // push/pull model for changing ownership IERC20 immutable OHM; // claim token IERC20 immutable DAI; // payment token ITreasury immutable treasury; // mints claim token IStaking immutable staking; // stake OHM for sOHM address immutable DAO; // holds non-circulating supply IwOHM immutable wOHM; // tracks rebase-agnostic balance bool public useStatic; // track 1/3 as static. governance can disable if desired. mapping( address => Term ) public terms; // tracks address info mapping( address => address ) public walletChange; // facilitates address change uint public totalAllocated; // as percent of supply (4 decimals: 10000 = 1%) uint public maximumAllocated; // maximum portion of supply can allocate /* ========== CONSTRUCTOR ========== */ constructor( address _ohm, address _dai, address _treasury, address _DAO, address _wOHM, address _staking, uint _maximumAllocated ) { owner = msg.sender; require( _ohm != address(0) ); OHM = IERC20( _ohm ); require( _dai != address(0) ); DAI = IERC20( _dai ); require( _treasury != address(0) ); treasury = ITreasury( _treasury ); require( _DAO != address(0) ); DAO = _DAO; require( _wOHM != address(0) ); wOHM = IwOHM( _wOHM ); require( _staking != address(0) ); staking = IStaking( _staking ); maximumAllocated = _maximumAllocated; useStatic = true; } /* ========== USER FUNCTIONS ========== */ /** * @notice allows wallet to claim OHM * @param _amount uint */ function claim( uint _amount ) external { OHM.safeTransfer( msg.sender, _claim( _amount ) ); } /** * @notice allows wallet to claim OHM and stake. set _claim = true if warmup is 0. * @param _amount uint * @param _claimsOHM bool */ function stake( uint _amount, bool _claimsOHM ) external { uint toStake = _claim( _amount ); OHM.approve( address( staking ), toStake ); staking.stake( toStake, msg.sender ); if ( _claimsOHM ) { staking.claim( msg.sender ); } } /** * @notice logic for claiming OHM * @param _amount uint * @return ToSend_ uint */ function _claim( uint _amount ) internal returns ( uint ToSend_ ) { Term memory info = terms[ msg.sender ]; DAI.safeTransferFrom( msg.sender, address( this ), _amount ); DAI.approve( address( treasury ), _amount ); ToSend_ = treasury.deposit( _amount, address( DAI ), 0 ); require( redeemableFor( msg.sender ).div( 1e9 ) >= ToSend_, 'Not enough vested' ); require( info.max.sub( claimed( msg.sender ) ) >= ToSend_, 'Claimed over max' ); if( useStatic ) { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_.mul( 2 ).div( 3 ) ) ); terms[ msg.sender ].claimed = info.claimed.add( ToSend_.div( 3 ) ); } else { terms[ msg.sender ].wClaimed = info.wClaimed.add( wOHM.sOHMTowOHM( ToSend_ ) ); } } /** * @notice allows address to push terms to new address * @param _newAddress address */ function pushWalletChange( address _newAddress ) external { require( terms[ msg.sender ].percent != 0 ); walletChange[ msg.sender ] = _newAddress; } /** * @notice allows new address to pull terms * @param _oldAddress address */ function pullWalletChange( address _oldAddress ) external { require( walletChange[ _oldAddress ] == msg.sender, "wallet did not push" ); walletChange[ _oldAddress ] = address(0); terms[ msg.sender ] = terms[ _oldAddress ]; delete terms[ _oldAddress ]; } /* ========== VIEW FUNCTIONS ========== */ /** * @notice view OHM claimable for address. DAI decimals (18). * @param _address address * @return uint */ function redeemableFor( address _address ) public view returns (uint) { uint max = circulatingSupply().mul( terms[ _address ].percent ).mul( 1e3 ); return max.sub( claimed( _address ).mul( 1e9 ) ); } /** * @notice view OHM claimed by address. OHM decimals (9). * @param _address address * @return uint */ function claimed( address _address ) public view returns ( uint ) { return wOHM.wOHMTosOHM( terms[ _address ].wClaimed ).add( terms[ _address ].claimed ); } /** * @notice view circulating supply of OHM * @notice calculated as total supply minus DAO holdings * @return uint */ function circulatingSupply() public view returns ( uint ) { return OHM.totalSupply().sub( OHM.balanceOf( DAO ) ); } /* ========== OWNER FUNCTIONS ========== */ /** * @notice set terms for new address * @notice cannot lower for address or exceed maximum total allocation * @param _address address * @param _amountCanClaim uint * @param _rate uint * @param _hasClaimed uint */ function setTerms(address _address, uint _amountCanClaim, uint _rate, uint _hasClaimed ) external { require( msg.sender == owner, "Sender is not owner" ); require( _amountCanClaim >= terms[ _address ].max, "cannot lower amount claimable" ); require( _rate >= terms[ _address ].percent, "cannot lower vesting rate" ); require( totalAllocated.add( _rate ) <= maximumAllocated, "Cannot allocate more" ); if( terms[ _address ].max == 0 ) { terms[ _address ].wClaimed = wOHM.sOHMTowOHM( _hasClaimed ); } terms[ _address ].max = _amountCanClaim; terms[ _address ].percent = _rate; totalAllocated = totalAllocated.add( _rate ); } /** * @notice push ownership of contract * @param _newOwner address */ function pushOwnership( address _newOwner ) external { require( msg.sender == owner, "Sender is not owner" ); require( _newOwner != address(0) ); newOwner = _newOwner; } /** * @notice pull ownership of contract */ function pullOwnership() external { require( msg.sender == newOwner ); owner = newOwner; newOwner = address(0); } /** * @notice renounce ownership of contract (no owner) */ function renounceOwnership() external { require( msg.sender == owner, "Sender is not owner" ); owner = address(0); newOwner = address(0); } /* ========== DAO FUNCTIONS ========== */ /** * @notice all claims tracked under wClaimed (and track rebase) */ function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; } }
/** * This contract allows Olympus genesis contributors to claim OHM. It has been * revised to consider 2/3 tokens as staked at the time of claim; previously, * no claims were treated as staked. This change keeps network ownership in check. * 100% can be treated as staked, if the DAO sees fit to do so. */
NatSpecMultiLine
treatAllAsStaked
function treatAllAsStaked() external { require( msg.sender == DAO, "Sender is not DAO" ); useStatic = false; }
/** * @notice all claims tracked under wClaimed (and track rebase) */
NatSpecMultiLine
v0.7.5+commit.eb77ed08
Unknown
ipfs://5a515a354374dc9dd911960dee7091835ca7ba191068dea401122cc4c67afa84
{ "func_code_index": [ 7623, 7763 ] }
7,923
Master
contracts/external/ERC20Detailed.sol
0x26d93492ce054fe4ac0181998fa9965a2b6d948d
Solidity
ERC20Detailed
contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of * these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. * * > Note that this information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * `IERC20.balanceOf` and `IERC20.transfer`. */ function decimals() public view returns (uint8) { return _decimals; } }
/** * @dev Optional functions from the ERC20 standard. */
NatSpecMultiLine
name
function name() public view returns (string memory) { return _name; }
/** * @dev Returns the name of the token. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
None
bzzr://9e44dfd319eadf914d318b449a2ad6c42edb3330632184b0da6ff7b44b75a83f
{ "func_code_index": [ 550, 638 ] }
7,924
Master
contracts/external/ERC20Detailed.sol
0x26d93492ce054fe4ac0181998fa9965a2b6d948d
Solidity
ERC20Detailed
contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of * these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. * * > Note that this information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * `IERC20.balanceOf` and `IERC20.transfer`. */ function decimals() public view returns (uint8) { return _decimals; } }
/** * @dev Optional functions from the ERC20 standard. */
NatSpecMultiLine
symbol
function symbol() public view returns (string memory) { return _symbol; }
/** * @dev Returns the symbol of the token, usually a shorter version of the * name. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
None
bzzr://9e44dfd319eadf914d318b449a2ad6c42edb3330632184b0da6ff7b44b75a83f
{ "func_code_index": [ 752, 844 ] }
7,925
Master
contracts/external/ERC20Detailed.sol
0x26d93492ce054fe4ac0181998fa9965a2b6d948d
Solidity
ERC20Detailed
contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of * these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. * * > Note that this information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * `IERC20.balanceOf` and `IERC20.transfer`. */ function decimals() public view returns (uint8) { return _decimals; } }
/** * @dev Optional functions from the ERC20 standard. */
NatSpecMultiLine
decimals
function decimals() public view returns (uint8) { return _decimals; }
/** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. * * > Note that this information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * `IERC20.balanceOf` and `IERC20.transfer`. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
None
bzzr://9e44dfd319eadf914d318b449a2ad6c42edb3330632184b0da6ff7b44b75a83f
{ "func_code_index": [ 1408, 1496 ] }
7,926
Raffle
contracts/AccessControl/RaffleAdminAccessControl.sol
0x13838388afa16c7a2507dd65feb961b53bb7b78c
Solidity
RaffleAdminAccessControl
contract RaffleAdminAccessControl is AccessControlEnumerable { bytes32 public constant RAFFLE_MANAGER_ROLE = keccak256("RAFFLE_MANAGER_ROLE"); bytes32 public constant PRIZE_MANAGER_ROLE = keccak256("PRIZE_MANAGER_ROLE"); address public managerOf; event RaffleManagerAdded(address indexed account, address managerOf); event RaffleManagerRemoved(address indexed account, address managerOf); event PrizeManagerAdded(address indexed account, address managerOf); event PrizeManagerRemoved(address indexed account, address managerOf); /** * @dev Constructor Add the given account both as the main Admin of the smart contract and a checkpoint admin * @param raffleOwner The account that will be added as raffleOwner */ constructor (address raffleOwner, address _managerOf) { require( raffleOwner != address(0), "Raffle owner should be a valid address" ); managerOf = _managerOf; _setupRole(DEFAULT_ADMIN_ROLE, raffleOwner); _setupRole(PRIZE_MANAGER_ROLE, raffleOwner); _setupRole(RAFFLE_MANAGER_ROLE, raffleOwner); } modifier onlyAdmin() { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "RaffleAdminAccessControl: Only admin role"); _; } modifier onlyManager() { require(hasRole(RAFFLE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only manager role"); _; } modifier onlyPrizeManager() { require(hasRole(PRIZE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only prize manager role"); _; } /** * @dev Adds a new account to the manager role * @param account The account that will have the manager role */ function addRaffleManager(address account) public onlyAdmin { grantRole(RAFFLE_MANAGER_ROLE, account); emit RaffleManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the manager role */ function renounceRaffleManager() public { renounceRole(RAFFLE_MANAGER_ROLE, msg.sender); emit RaffleManagerRemoved(msg.sender, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isRaffleManager(address account) public view returns (bool) { return hasRole(RAFFLE_MANAGER_ROLE, account); } /** * @dev Removes the given account from the manager role, if msg.sender is manager * @param manager The account that will have the manager role removed */ function removeRaffleManager(address manager) public onlyAdmin { revokeRole(RAFFLE_MANAGER_ROLE, manager); emit RaffleManagerRemoved(manager, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isPrizeManager(address account) public view returns (bool) { return hasRole(PRIZE_MANAGER_ROLE, account); } /** * @dev Adds a new account to the prizeManager role * @param account The account that will have the prizeManager role */ function addPrizeManager(address account) public onlyAdmin virtual { grantRole(PRIZE_MANAGER_ROLE, account); emit PrizeManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the prizeManager role */ function renouncePrizeManager() public { renounceRole(PRIZE_MANAGER_ROLE, msg.sender); emit PrizeManagerRemoved(msg.sender, managerOf); } /** * @dev Removes the given account from the prizeManager role, if msg.sender is admin * @param prizeManager The account that will have the prizeManager role removed */ function removePrizeManager(address prizeManager) onlyAdmin public { revokeRole(PRIZE_MANAGER_ROLE, prizeManager); emit PrizeManagerRemoved(prizeManager, managerOf); } }
addRaffleManager
function addRaffleManager(address account) public onlyAdmin { grantRole(RAFFLE_MANAGER_ROLE, account); emit RaffleManagerAdded(account, managerOf); }
/** * @dev Adds a new account to the manager role * @param account The account that will have the manager role */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
{ "func_code_index": [ 1629, 1791 ] }
7,927
Raffle
contracts/AccessControl/RaffleAdminAccessControl.sol
0x13838388afa16c7a2507dd65feb961b53bb7b78c
Solidity
RaffleAdminAccessControl
contract RaffleAdminAccessControl is AccessControlEnumerable { bytes32 public constant RAFFLE_MANAGER_ROLE = keccak256("RAFFLE_MANAGER_ROLE"); bytes32 public constant PRIZE_MANAGER_ROLE = keccak256("PRIZE_MANAGER_ROLE"); address public managerOf; event RaffleManagerAdded(address indexed account, address managerOf); event RaffleManagerRemoved(address indexed account, address managerOf); event PrizeManagerAdded(address indexed account, address managerOf); event PrizeManagerRemoved(address indexed account, address managerOf); /** * @dev Constructor Add the given account both as the main Admin of the smart contract and a checkpoint admin * @param raffleOwner The account that will be added as raffleOwner */ constructor (address raffleOwner, address _managerOf) { require( raffleOwner != address(0), "Raffle owner should be a valid address" ); managerOf = _managerOf; _setupRole(DEFAULT_ADMIN_ROLE, raffleOwner); _setupRole(PRIZE_MANAGER_ROLE, raffleOwner); _setupRole(RAFFLE_MANAGER_ROLE, raffleOwner); } modifier onlyAdmin() { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "RaffleAdminAccessControl: Only admin role"); _; } modifier onlyManager() { require(hasRole(RAFFLE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only manager role"); _; } modifier onlyPrizeManager() { require(hasRole(PRIZE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only prize manager role"); _; } /** * @dev Adds a new account to the manager role * @param account The account that will have the manager role */ function addRaffleManager(address account) public onlyAdmin { grantRole(RAFFLE_MANAGER_ROLE, account); emit RaffleManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the manager role */ function renounceRaffleManager() public { renounceRole(RAFFLE_MANAGER_ROLE, msg.sender); emit RaffleManagerRemoved(msg.sender, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isRaffleManager(address account) public view returns (bool) { return hasRole(RAFFLE_MANAGER_ROLE, account); } /** * @dev Removes the given account from the manager role, if msg.sender is manager * @param manager The account that will have the manager role removed */ function removeRaffleManager(address manager) public onlyAdmin { revokeRole(RAFFLE_MANAGER_ROLE, manager); emit RaffleManagerRemoved(manager, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isPrizeManager(address account) public view returns (bool) { return hasRole(PRIZE_MANAGER_ROLE, account); } /** * @dev Adds a new account to the prizeManager role * @param account The account that will have the prizeManager role */ function addPrizeManager(address account) public onlyAdmin virtual { grantRole(PRIZE_MANAGER_ROLE, account); emit PrizeManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the prizeManager role */ function renouncePrizeManager() public { renounceRole(PRIZE_MANAGER_ROLE, msg.sender); emit PrizeManagerRemoved(msg.sender, managerOf); } /** * @dev Removes the given account from the prizeManager role, if msg.sender is admin * @param prizeManager The account that will have the prizeManager role removed */ function removePrizeManager(address prizeManager) onlyAdmin public { revokeRole(PRIZE_MANAGER_ROLE, prizeManager); emit PrizeManagerRemoved(prizeManager, managerOf); } }
renounceRaffleManager
function renounceRaffleManager() public { renounceRole(RAFFLE_MANAGER_ROLE, msg.sender); emit RaffleManagerRemoved(msg.sender, managerOf); }
/** * @dev Removes the sender from the list the manager role */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
{ "func_code_index": [ 1863, 2016 ] }
7,928
Raffle
contracts/AccessControl/RaffleAdminAccessControl.sol
0x13838388afa16c7a2507dd65feb961b53bb7b78c
Solidity
RaffleAdminAccessControl
contract RaffleAdminAccessControl is AccessControlEnumerable { bytes32 public constant RAFFLE_MANAGER_ROLE = keccak256("RAFFLE_MANAGER_ROLE"); bytes32 public constant PRIZE_MANAGER_ROLE = keccak256("PRIZE_MANAGER_ROLE"); address public managerOf; event RaffleManagerAdded(address indexed account, address managerOf); event RaffleManagerRemoved(address indexed account, address managerOf); event PrizeManagerAdded(address indexed account, address managerOf); event PrizeManagerRemoved(address indexed account, address managerOf); /** * @dev Constructor Add the given account both as the main Admin of the smart contract and a checkpoint admin * @param raffleOwner The account that will be added as raffleOwner */ constructor (address raffleOwner, address _managerOf) { require( raffleOwner != address(0), "Raffle owner should be a valid address" ); managerOf = _managerOf; _setupRole(DEFAULT_ADMIN_ROLE, raffleOwner); _setupRole(PRIZE_MANAGER_ROLE, raffleOwner); _setupRole(RAFFLE_MANAGER_ROLE, raffleOwner); } modifier onlyAdmin() { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "RaffleAdminAccessControl: Only admin role"); _; } modifier onlyManager() { require(hasRole(RAFFLE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only manager role"); _; } modifier onlyPrizeManager() { require(hasRole(PRIZE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only prize manager role"); _; } /** * @dev Adds a new account to the manager role * @param account The account that will have the manager role */ function addRaffleManager(address account) public onlyAdmin { grantRole(RAFFLE_MANAGER_ROLE, account); emit RaffleManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the manager role */ function renounceRaffleManager() public { renounceRole(RAFFLE_MANAGER_ROLE, msg.sender); emit RaffleManagerRemoved(msg.sender, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isRaffleManager(address account) public view returns (bool) { return hasRole(RAFFLE_MANAGER_ROLE, account); } /** * @dev Removes the given account from the manager role, if msg.sender is manager * @param manager The account that will have the manager role removed */ function removeRaffleManager(address manager) public onlyAdmin { revokeRole(RAFFLE_MANAGER_ROLE, manager); emit RaffleManagerRemoved(manager, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isPrizeManager(address account) public view returns (bool) { return hasRole(PRIZE_MANAGER_ROLE, account); } /** * @dev Adds a new account to the prizeManager role * @param account The account that will have the prizeManager role */ function addPrizeManager(address account) public onlyAdmin virtual { grantRole(PRIZE_MANAGER_ROLE, account); emit PrizeManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the prizeManager role */ function renouncePrizeManager() public { renounceRole(PRIZE_MANAGER_ROLE, msg.sender); emit PrizeManagerRemoved(msg.sender, managerOf); } /** * @dev Removes the given account from the prizeManager role, if msg.sender is admin * @param prizeManager The account that will have the prizeManager role removed */ function removePrizeManager(address prizeManager) onlyAdmin public { revokeRole(PRIZE_MANAGER_ROLE, prizeManager); emit PrizeManagerRemoved(prizeManager, managerOf); } }
isRaffleManager
function isRaffleManager(address account) public view returns (bool) { return hasRole(RAFFLE_MANAGER_ROLE, account); }
/** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
{ "func_code_index": [ 2136, 2262 ] }
7,929
Raffle
contracts/AccessControl/RaffleAdminAccessControl.sol
0x13838388afa16c7a2507dd65feb961b53bb7b78c
Solidity
RaffleAdminAccessControl
contract RaffleAdminAccessControl is AccessControlEnumerable { bytes32 public constant RAFFLE_MANAGER_ROLE = keccak256("RAFFLE_MANAGER_ROLE"); bytes32 public constant PRIZE_MANAGER_ROLE = keccak256("PRIZE_MANAGER_ROLE"); address public managerOf; event RaffleManagerAdded(address indexed account, address managerOf); event RaffleManagerRemoved(address indexed account, address managerOf); event PrizeManagerAdded(address indexed account, address managerOf); event PrizeManagerRemoved(address indexed account, address managerOf); /** * @dev Constructor Add the given account both as the main Admin of the smart contract and a checkpoint admin * @param raffleOwner The account that will be added as raffleOwner */ constructor (address raffleOwner, address _managerOf) { require( raffleOwner != address(0), "Raffle owner should be a valid address" ); managerOf = _managerOf; _setupRole(DEFAULT_ADMIN_ROLE, raffleOwner); _setupRole(PRIZE_MANAGER_ROLE, raffleOwner); _setupRole(RAFFLE_MANAGER_ROLE, raffleOwner); } modifier onlyAdmin() { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "RaffleAdminAccessControl: Only admin role"); _; } modifier onlyManager() { require(hasRole(RAFFLE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only manager role"); _; } modifier onlyPrizeManager() { require(hasRole(PRIZE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only prize manager role"); _; } /** * @dev Adds a new account to the manager role * @param account The account that will have the manager role */ function addRaffleManager(address account) public onlyAdmin { grantRole(RAFFLE_MANAGER_ROLE, account); emit RaffleManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the manager role */ function renounceRaffleManager() public { renounceRole(RAFFLE_MANAGER_ROLE, msg.sender); emit RaffleManagerRemoved(msg.sender, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isRaffleManager(address account) public view returns (bool) { return hasRole(RAFFLE_MANAGER_ROLE, account); } /** * @dev Removes the given account from the manager role, if msg.sender is manager * @param manager The account that will have the manager role removed */ function removeRaffleManager(address manager) public onlyAdmin { revokeRole(RAFFLE_MANAGER_ROLE, manager); emit RaffleManagerRemoved(manager, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isPrizeManager(address account) public view returns (bool) { return hasRole(PRIZE_MANAGER_ROLE, account); } /** * @dev Adds a new account to the prizeManager role * @param account The account that will have the prizeManager role */ function addPrizeManager(address account) public onlyAdmin virtual { grantRole(PRIZE_MANAGER_ROLE, account); emit PrizeManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the prizeManager role */ function renouncePrizeManager() public { renounceRole(PRIZE_MANAGER_ROLE, msg.sender); emit PrizeManagerRemoved(msg.sender, managerOf); } /** * @dev Removes the given account from the prizeManager role, if msg.sender is admin * @param prizeManager The account that will have the prizeManager role removed */ function removePrizeManager(address prizeManager) onlyAdmin public { revokeRole(PRIZE_MANAGER_ROLE, prizeManager); emit PrizeManagerRemoved(prizeManager, managerOf); } }
removeRaffleManager
function removeRaffleManager(address manager) public onlyAdmin { revokeRole(RAFFLE_MANAGER_ROLE, manager); emit RaffleManagerRemoved(manager, managerOf); }
/** * @dev Removes the given account from the manager role, if msg.sender is manager * @param manager The account that will have the manager role removed */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
{ "func_code_index": [ 2429, 2597 ] }
7,930
Raffle
contracts/AccessControl/RaffleAdminAccessControl.sol
0x13838388afa16c7a2507dd65feb961b53bb7b78c
Solidity
RaffleAdminAccessControl
contract RaffleAdminAccessControl is AccessControlEnumerable { bytes32 public constant RAFFLE_MANAGER_ROLE = keccak256("RAFFLE_MANAGER_ROLE"); bytes32 public constant PRIZE_MANAGER_ROLE = keccak256("PRIZE_MANAGER_ROLE"); address public managerOf; event RaffleManagerAdded(address indexed account, address managerOf); event RaffleManagerRemoved(address indexed account, address managerOf); event PrizeManagerAdded(address indexed account, address managerOf); event PrizeManagerRemoved(address indexed account, address managerOf); /** * @dev Constructor Add the given account both as the main Admin of the smart contract and a checkpoint admin * @param raffleOwner The account that will be added as raffleOwner */ constructor (address raffleOwner, address _managerOf) { require( raffleOwner != address(0), "Raffle owner should be a valid address" ); managerOf = _managerOf; _setupRole(DEFAULT_ADMIN_ROLE, raffleOwner); _setupRole(PRIZE_MANAGER_ROLE, raffleOwner); _setupRole(RAFFLE_MANAGER_ROLE, raffleOwner); } modifier onlyAdmin() { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "RaffleAdminAccessControl: Only admin role"); _; } modifier onlyManager() { require(hasRole(RAFFLE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only manager role"); _; } modifier onlyPrizeManager() { require(hasRole(PRIZE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only prize manager role"); _; } /** * @dev Adds a new account to the manager role * @param account The account that will have the manager role */ function addRaffleManager(address account) public onlyAdmin { grantRole(RAFFLE_MANAGER_ROLE, account); emit RaffleManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the manager role */ function renounceRaffleManager() public { renounceRole(RAFFLE_MANAGER_ROLE, msg.sender); emit RaffleManagerRemoved(msg.sender, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isRaffleManager(address account) public view returns (bool) { return hasRole(RAFFLE_MANAGER_ROLE, account); } /** * @dev Removes the given account from the manager role, if msg.sender is manager * @param manager The account that will have the manager role removed */ function removeRaffleManager(address manager) public onlyAdmin { revokeRole(RAFFLE_MANAGER_ROLE, manager); emit RaffleManagerRemoved(manager, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isPrizeManager(address account) public view returns (bool) { return hasRole(PRIZE_MANAGER_ROLE, account); } /** * @dev Adds a new account to the prizeManager role * @param account The account that will have the prizeManager role */ function addPrizeManager(address account) public onlyAdmin virtual { grantRole(PRIZE_MANAGER_ROLE, account); emit PrizeManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the prizeManager role */ function renouncePrizeManager() public { renounceRole(PRIZE_MANAGER_ROLE, msg.sender); emit PrizeManagerRemoved(msg.sender, managerOf); } /** * @dev Removes the given account from the prizeManager role, if msg.sender is admin * @param prizeManager The account that will have the prizeManager role removed */ function removePrizeManager(address prizeManager) onlyAdmin public { revokeRole(PRIZE_MANAGER_ROLE, prizeManager); emit PrizeManagerRemoved(prizeManager, managerOf); } }
isPrizeManager
function isPrizeManager(address account) public view returns (bool) { return hasRole(PRIZE_MANAGER_ROLE, account); }
/** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
{ "func_code_index": [ 2723, 2850 ] }
7,931
Raffle
contracts/AccessControl/RaffleAdminAccessControl.sol
0x13838388afa16c7a2507dd65feb961b53bb7b78c
Solidity
RaffleAdminAccessControl
contract RaffleAdminAccessControl is AccessControlEnumerable { bytes32 public constant RAFFLE_MANAGER_ROLE = keccak256("RAFFLE_MANAGER_ROLE"); bytes32 public constant PRIZE_MANAGER_ROLE = keccak256("PRIZE_MANAGER_ROLE"); address public managerOf; event RaffleManagerAdded(address indexed account, address managerOf); event RaffleManagerRemoved(address indexed account, address managerOf); event PrizeManagerAdded(address indexed account, address managerOf); event PrizeManagerRemoved(address indexed account, address managerOf); /** * @dev Constructor Add the given account both as the main Admin of the smart contract and a checkpoint admin * @param raffleOwner The account that will be added as raffleOwner */ constructor (address raffleOwner, address _managerOf) { require( raffleOwner != address(0), "Raffle owner should be a valid address" ); managerOf = _managerOf; _setupRole(DEFAULT_ADMIN_ROLE, raffleOwner); _setupRole(PRIZE_MANAGER_ROLE, raffleOwner); _setupRole(RAFFLE_MANAGER_ROLE, raffleOwner); } modifier onlyAdmin() { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "RaffleAdminAccessControl: Only admin role"); _; } modifier onlyManager() { require(hasRole(RAFFLE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only manager role"); _; } modifier onlyPrizeManager() { require(hasRole(PRIZE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only prize manager role"); _; } /** * @dev Adds a new account to the manager role * @param account The account that will have the manager role */ function addRaffleManager(address account) public onlyAdmin { grantRole(RAFFLE_MANAGER_ROLE, account); emit RaffleManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the manager role */ function renounceRaffleManager() public { renounceRole(RAFFLE_MANAGER_ROLE, msg.sender); emit RaffleManagerRemoved(msg.sender, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isRaffleManager(address account) public view returns (bool) { return hasRole(RAFFLE_MANAGER_ROLE, account); } /** * @dev Removes the given account from the manager role, if msg.sender is manager * @param manager The account that will have the manager role removed */ function removeRaffleManager(address manager) public onlyAdmin { revokeRole(RAFFLE_MANAGER_ROLE, manager); emit RaffleManagerRemoved(manager, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isPrizeManager(address account) public view returns (bool) { return hasRole(PRIZE_MANAGER_ROLE, account); } /** * @dev Adds a new account to the prizeManager role * @param account The account that will have the prizeManager role */ function addPrizeManager(address account) public onlyAdmin virtual { grantRole(PRIZE_MANAGER_ROLE, account); emit PrizeManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the prizeManager role */ function renouncePrizeManager() public { renounceRole(PRIZE_MANAGER_ROLE, msg.sender); emit PrizeManagerRemoved(msg.sender, managerOf); } /** * @dev Removes the given account from the prizeManager role, if msg.sender is admin * @param prizeManager The account that will have the prizeManager role removed */ function removePrizeManager(address prizeManager) onlyAdmin public { revokeRole(PRIZE_MANAGER_ROLE, prizeManager); emit PrizeManagerRemoved(prizeManager, managerOf); } }
addPrizeManager
function addPrizeManager(address account) public onlyAdmin virtual { grantRole(PRIZE_MANAGER_ROLE, account); emit PrizeManagerAdded(account, managerOf); }
/** * @dev Adds a new account to the prizeManager role * @param account The account that will have the prizeManager role */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
{ "func_code_index": [ 2991, 3162 ] }
7,932
Raffle
contracts/AccessControl/RaffleAdminAccessControl.sol
0x13838388afa16c7a2507dd65feb961b53bb7b78c
Solidity
RaffleAdminAccessControl
contract RaffleAdminAccessControl is AccessControlEnumerable { bytes32 public constant RAFFLE_MANAGER_ROLE = keccak256("RAFFLE_MANAGER_ROLE"); bytes32 public constant PRIZE_MANAGER_ROLE = keccak256("PRIZE_MANAGER_ROLE"); address public managerOf; event RaffleManagerAdded(address indexed account, address managerOf); event RaffleManagerRemoved(address indexed account, address managerOf); event PrizeManagerAdded(address indexed account, address managerOf); event PrizeManagerRemoved(address indexed account, address managerOf); /** * @dev Constructor Add the given account both as the main Admin of the smart contract and a checkpoint admin * @param raffleOwner The account that will be added as raffleOwner */ constructor (address raffleOwner, address _managerOf) { require( raffleOwner != address(0), "Raffle owner should be a valid address" ); managerOf = _managerOf; _setupRole(DEFAULT_ADMIN_ROLE, raffleOwner); _setupRole(PRIZE_MANAGER_ROLE, raffleOwner); _setupRole(RAFFLE_MANAGER_ROLE, raffleOwner); } modifier onlyAdmin() { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "RaffleAdminAccessControl: Only admin role"); _; } modifier onlyManager() { require(hasRole(RAFFLE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only manager role"); _; } modifier onlyPrizeManager() { require(hasRole(PRIZE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only prize manager role"); _; } /** * @dev Adds a new account to the manager role * @param account The account that will have the manager role */ function addRaffleManager(address account) public onlyAdmin { grantRole(RAFFLE_MANAGER_ROLE, account); emit RaffleManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the manager role */ function renounceRaffleManager() public { renounceRole(RAFFLE_MANAGER_ROLE, msg.sender); emit RaffleManagerRemoved(msg.sender, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isRaffleManager(address account) public view returns (bool) { return hasRole(RAFFLE_MANAGER_ROLE, account); } /** * @dev Removes the given account from the manager role, if msg.sender is manager * @param manager The account that will have the manager role removed */ function removeRaffleManager(address manager) public onlyAdmin { revokeRole(RAFFLE_MANAGER_ROLE, manager); emit RaffleManagerRemoved(manager, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isPrizeManager(address account) public view returns (bool) { return hasRole(PRIZE_MANAGER_ROLE, account); } /** * @dev Adds a new account to the prizeManager role * @param account The account that will have the prizeManager role */ function addPrizeManager(address account) public onlyAdmin virtual { grantRole(PRIZE_MANAGER_ROLE, account); emit PrizeManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the prizeManager role */ function renouncePrizeManager() public { renounceRole(PRIZE_MANAGER_ROLE, msg.sender); emit PrizeManagerRemoved(msg.sender, managerOf); } /** * @dev Removes the given account from the prizeManager role, if msg.sender is admin * @param prizeManager The account that will have the prizeManager role removed */ function removePrizeManager(address prizeManager) onlyAdmin public { revokeRole(PRIZE_MANAGER_ROLE, prizeManager); emit PrizeManagerRemoved(prizeManager, managerOf); } }
renouncePrizeManager
function renouncePrizeManager() public { renounceRole(PRIZE_MANAGER_ROLE, msg.sender); emit PrizeManagerRemoved(msg.sender, managerOf); }
/** * @dev Removes the sender from the list the prizeManager role */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
{ "func_code_index": [ 3244, 3398 ] }
7,933
Raffle
contracts/AccessControl/RaffleAdminAccessControl.sol
0x13838388afa16c7a2507dd65feb961b53bb7b78c
Solidity
RaffleAdminAccessControl
contract RaffleAdminAccessControl is AccessControlEnumerable { bytes32 public constant RAFFLE_MANAGER_ROLE = keccak256("RAFFLE_MANAGER_ROLE"); bytes32 public constant PRIZE_MANAGER_ROLE = keccak256("PRIZE_MANAGER_ROLE"); address public managerOf; event RaffleManagerAdded(address indexed account, address managerOf); event RaffleManagerRemoved(address indexed account, address managerOf); event PrizeManagerAdded(address indexed account, address managerOf); event PrizeManagerRemoved(address indexed account, address managerOf); /** * @dev Constructor Add the given account both as the main Admin of the smart contract and a checkpoint admin * @param raffleOwner The account that will be added as raffleOwner */ constructor (address raffleOwner, address _managerOf) { require( raffleOwner != address(0), "Raffle owner should be a valid address" ); managerOf = _managerOf; _setupRole(DEFAULT_ADMIN_ROLE, raffleOwner); _setupRole(PRIZE_MANAGER_ROLE, raffleOwner); _setupRole(RAFFLE_MANAGER_ROLE, raffleOwner); } modifier onlyAdmin() { require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "RaffleAdminAccessControl: Only admin role"); _; } modifier onlyManager() { require(hasRole(RAFFLE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only manager role"); _; } modifier onlyPrizeManager() { require(hasRole(PRIZE_MANAGER_ROLE, msg.sender), "RaffleAdminAccessControl: Only prize manager role"); _; } /** * @dev Adds a new account to the manager role * @param account The account that will have the manager role */ function addRaffleManager(address account) public onlyAdmin { grantRole(RAFFLE_MANAGER_ROLE, account); emit RaffleManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the manager role */ function renounceRaffleManager() public { renounceRole(RAFFLE_MANAGER_ROLE, msg.sender); emit RaffleManagerRemoved(msg.sender, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isRaffleManager(address account) public view returns (bool) { return hasRole(RAFFLE_MANAGER_ROLE, account); } /** * @dev Removes the given account from the manager role, if msg.sender is manager * @param manager The account that will have the manager role removed */ function removeRaffleManager(address manager) public onlyAdmin { revokeRole(RAFFLE_MANAGER_ROLE, manager); emit RaffleManagerRemoved(manager, managerOf); } /** * @dev checks if the given account is a prizeManager * @param account The account that will be checked */ function isPrizeManager(address account) public view returns (bool) { return hasRole(PRIZE_MANAGER_ROLE, account); } /** * @dev Adds a new account to the prizeManager role * @param account The account that will have the prizeManager role */ function addPrizeManager(address account) public onlyAdmin virtual { grantRole(PRIZE_MANAGER_ROLE, account); emit PrizeManagerAdded(account, managerOf); } /** * @dev Removes the sender from the list the prizeManager role */ function renouncePrizeManager() public { renounceRole(PRIZE_MANAGER_ROLE, msg.sender); emit PrizeManagerRemoved(msg.sender, managerOf); } /** * @dev Removes the given account from the prizeManager role, if msg.sender is admin * @param prizeManager The account that will have the prizeManager role removed */ function removePrizeManager(address prizeManager) onlyAdmin public { revokeRole(PRIZE_MANAGER_ROLE, prizeManager); emit PrizeManagerRemoved(prizeManager, managerOf); } }
removePrizeManager
function removePrizeManager(address prizeManager) onlyAdmin public { revokeRole(PRIZE_MANAGER_ROLE, prizeManager); emit PrizeManagerRemoved(prizeManager, managerOf); }
/** * @dev Removes the given account from the prizeManager role, if msg.sender is admin * @param prizeManager The account that will have the prizeManager role removed */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
{ "func_code_index": [ 3585, 3769 ] }
7,934
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
Buffer
library Buffer { struct buffer { bytes buf; uint capacity; } function init(buffer memory buf, uint _capacity) internal pure { uint capacity = _capacity; if(capacity % 32 != 0) capacity += 32 - (capacity % 32); // Allocate space for the buffer data buf.capacity = capacity; assembly { let ptr := mload(0x40) mstore(buf, ptr) mstore(ptr, 0) mstore(0x40, add(ptr, capacity)) } } function resize(buffer memory buf, uint capacity) private pure { bytes memory oldbuf = buf.buf; init(buf, capacity); append(buf, oldbuf); } function max(uint a, uint b) private pure returns(uint) { if(a > b) { return a; } return b; } /** * @dev Appends a byte array to the end of the buffer. Resizes if doing so * would exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, bytes data) internal pure returns(buffer memory) { if(data.length + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, data.length) * 2); } uint dest; uint src; uint len = data.length; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Start address = buffer address + buffer length + sizeof(buffer length) dest := add(add(bufptr, buflen), 32) // Update buffer length mstore(bufptr, add(buflen, mload(data))) src := add(data, 32) } // Copy word-length chunks while possible for(; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } return buf; } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, uint8 data) internal pure { if(buf.buf.length + 1 > buf.capacity) { resize(buf, buf.capacity * 2); } assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) let dest := add(add(bufptr, buflen), 32) mstore8(dest, data) // Update buffer length mstore(bufptr, add(buflen, 1)) } } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) { if(len + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, len) * 2); } uint mask = 256 ** len - 1; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) + len let dest := add(add(bufptr, buflen), len) mstore(dest, or(and(mload(dest), not(mask)), data)) // Update buffer length mstore(bufptr, add(buflen, len)) } return buf; } }
/* Begin solidity-cborutils https://github.com/smartcontractkit/solidity-cborutils MIT License Copyright (c) 2018 SmartContract ChainLink, Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
Comment
append
function append(buffer memory buf, bytes data) internal pure returns(buffer memory) { if(data.length + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, data.length) * 2); } uint dest; uint src; uint len = data.length; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Start address = buffer address + buffer length + sizeof(buffer length) dest := add(add(bufptr, buflen), 32) // Update buffer length mstore(bufptr, add(buflen, mload(data))) src := add(data, 32) } // Copy word-length chunks while possible for(; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } return buf; }
/** * @dev Appends a byte array to the end of the buffer. Resizes if doing so * would exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 1123, 2417 ] }
7,935
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
Buffer
library Buffer { struct buffer { bytes buf; uint capacity; } function init(buffer memory buf, uint _capacity) internal pure { uint capacity = _capacity; if(capacity % 32 != 0) capacity += 32 - (capacity % 32); // Allocate space for the buffer data buf.capacity = capacity; assembly { let ptr := mload(0x40) mstore(buf, ptr) mstore(ptr, 0) mstore(0x40, add(ptr, capacity)) } } function resize(buffer memory buf, uint capacity) private pure { bytes memory oldbuf = buf.buf; init(buf, capacity); append(buf, oldbuf); } function max(uint a, uint b) private pure returns(uint) { if(a > b) { return a; } return b; } /** * @dev Appends a byte array to the end of the buffer. Resizes if doing so * would exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, bytes data) internal pure returns(buffer memory) { if(data.length + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, data.length) * 2); } uint dest; uint src; uint len = data.length; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Start address = buffer address + buffer length + sizeof(buffer length) dest := add(add(bufptr, buflen), 32) // Update buffer length mstore(bufptr, add(buflen, mload(data))) src := add(data, 32) } // Copy word-length chunks while possible for(; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } return buf; } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, uint8 data) internal pure { if(buf.buf.length + 1 > buf.capacity) { resize(buf, buf.capacity * 2); } assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) let dest := add(add(bufptr, buflen), 32) mstore8(dest, data) // Update buffer length mstore(bufptr, add(buflen, 1)) } } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) { if(len + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, len) * 2); } uint mask = 256 ** len - 1; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) + len let dest := add(add(bufptr, buflen), len) mstore(dest, or(and(mload(dest), not(mask)), data)) // Update buffer length mstore(bufptr, add(buflen, len)) } return buf; } }
/* Begin solidity-cborutils https://github.com/smartcontractkit/solidity-cborutils MIT License Copyright (c) 2018 SmartContract ChainLink, Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
Comment
append
function append(buffer memory buf, uint8 data) internal pure { if(buf.buf.length + 1 > buf.capacity) { resize(buf, buf.capacity * 2); } assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) let dest := add(add(bufptr, buflen), 32) mstore8(dest, data) // Update buffer length mstore(bufptr, add(buflen, 1)) } }
/** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 2682, 3318 ] }
7,936
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
Buffer
library Buffer { struct buffer { bytes buf; uint capacity; } function init(buffer memory buf, uint _capacity) internal pure { uint capacity = _capacity; if(capacity % 32 != 0) capacity += 32 - (capacity % 32); // Allocate space for the buffer data buf.capacity = capacity; assembly { let ptr := mload(0x40) mstore(buf, ptr) mstore(ptr, 0) mstore(0x40, add(ptr, capacity)) } } function resize(buffer memory buf, uint capacity) private pure { bytes memory oldbuf = buf.buf; init(buf, capacity); append(buf, oldbuf); } function max(uint a, uint b) private pure returns(uint) { if(a > b) { return a; } return b; } /** * @dev Appends a byte array to the end of the buffer. Resizes if doing so * would exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, bytes data) internal pure returns(buffer memory) { if(data.length + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, data.length) * 2); } uint dest; uint src; uint len = data.length; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Start address = buffer address + buffer length + sizeof(buffer length) dest := add(add(bufptr, buflen), 32) // Update buffer length mstore(bufptr, add(buflen, mload(data))) src := add(data, 32) } // Copy word-length chunks while possible for(; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } return buf; } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, uint8 data) internal pure { if(buf.buf.length + 1 > buf.capacity) { resize(buf, buf.capacity * 2); } assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) let dest := add(add(bufptr, buflen), 32) mstore8(dest, data) // Update buffer length mstore(bufptr, add(buflen, 1)) } } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) { if(len + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, len) * 2); } uint mask = 256 ** len - 1; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) + len let dest := add(add(bufptr, buflen), len) mstore(dest, or(and(mload(dest), not(mask)), data)) // Update buffer length mstore(bufptr, add(buflen, len)) } return buf; } }
/* Begin solidity-cborutils https://github.com/smartcontractkit/solidity-cborutils MIT License Copyright (c) 2018 SmartContract ChainLink, Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
Comment
appendInt
function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) { if(len + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, len) * 2); } uint mask = 256 ** len - 1; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) + len let dest := add(add(bufptr, buflen), len) mstore(dest, or(and(mload(dest), not(mask)), data)) // Update buffer length mstore(bufptr, add(buflen, len)) } return buf; }
/** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 3583, 4365 ] }
7,937
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
parseInt
function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); }
// parseInt
LineComment
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 27483, 27587 ] }
7,938
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
parseInt
function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; }
// parseInt(parseFloat*10^_b)
LineComment
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 27625, 28239 ] }
7,939
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
copyBytes
function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; }
// the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
LineComment
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 38942, 39633 ] }
7,940
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
safer_ecrecover
function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); }
// the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value
LineComment
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 39830, 40833 ] }
7,941
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
ecrecovery
function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); }
// the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
LineComment
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 40955, 42381 ] }
7,942
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
Crowdsale
contract Crowdsale is usingOraclize { using SafeMath for uint256; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward; token tokenReward; // amount of raised money in wei uint256 public weiRaised; /** * 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); constructor () public { //You will change this to your wallet where you need the ETH wallet = 0xE35120FbF4Fe6d9895cc8a93BD0796b5cB89e776; //Here will come the checksum address of token we got addressOfTokenUsedAsReward = 0x84Ed1B54fa1A26012E6fcA29d55B00BB15bb1deF; tokenReward = token(addressOfTokenUsedAsReward); } bool public started = true; function startSale() public { require (msg.sender == wallet); started = true; } function stopSale() public { require (msg.sender == wallet); started = false; } function changeWallet(address _wallet) public { require (msg.sender == wallet); wallet = _wallet; } function changeTokenReward(address _token) public { require(msg.sender==wallet); tokenReward = token(_token); addressOfTokenUsedAsReward = _token; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } mapping (bytes32 => address) public idToBeneficiary; mapping (bytes32 => uint) public idToWeiAmount; event newOraclizeQuery(string description); function __callback(bytes32 myid, string result) public { require (msg.sender == oraclize_cbAddress()); address beneficiary = idToBeneficiary[myid]; uint weiAmount = idToWeiAmount[myid]; uint ethToCents = parseInt(result,2); uint tokens = weiAmount.mul(ethToCents)/100; tokenReward.transfer(beneficiary, tokens); emit TokenPurchase(beneficiary, beneficiary, weiAmount, tokens); } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); } // send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { wallet.transfer(address(this).balance); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; } function withdrawTokens(uint256 _amount) public { require (msg.sender==wallet); tokenReward.transfer(wallet,_amount); } }
function () public payable { buyTokens(msg.sender); }
// fallback function can be used to buy tokens
LineComment
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 1572, 1636 ] }
7,943
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
Crowdsale
contract Crowdsale is usingOraclize { using SafeMath for uint256; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward; token tokenReward; // amount of raised money in wei uint256 public weiRaised; /** * 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); constructor () public { //You will change this to your wallet where you need the ETH wallet = 0xE35120FbF4Fe6d9895cc8a93BD0796b5cB89e776; //Here will come the checksum address of token we got addressOfTokenUsedAsReward = 0x84Ed1B54fa1A26012E6fcA29d55B00BB15bb1deF; tokenReward = token(addressOfTokenUsedAsReward); } bool public started = true; function startSale() public { require (msg.sender == wallet); started = true; } function stopSale() public { require (msg.sender == wallet); started = false; } function changeWallet(address _wallet) public { require (msg.sender == wallet); wallet = _wallet; } function changeTokenReward(address _token) public { require(msg.sender==wallet); tokenReward = token(_token); addressOfTokenUsedAsReward = _token; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } mapping (bytes32 => address) public idToBeneficiary; mapping (bytes32 => uint) public idToWeiAmount; event newOraclizeQuery(string description); function __callback(bytes32 myid, string result) public { require (msg.sender == oraclize_cbAddress()); address beneficiary = idToBeneficiary[myid]; uint weiAmount = idToWeiAmount[myid]; uint ethToCents = parseInt(result,2); uint tokens = weiAmount.mul(ethToCents)/100; tokenReward.transfer(beneficiary, tokens); emit TokenPurchase(beneficiary, beneficiary, weiAmount, tokens); } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); } // send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { wallet.transfer(address(this).balance); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; } function withdrawTokens(uint256 _amount) public { require (msg.sender==wallet); tokenReward.transfer(wallet,_amount); } }
buyTokens
function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); }
// low level token purchase function
LineComment
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 2272, 2840 ] }
7,944
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
Crowdsale
contract Crowdsale is usingOraclize { using SafeMath for uint256; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward; token tokenReward; // amount of raised money in wei uint256 public weiRaised; /** * 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); constructor () public { //You will change this to your wallet where you need the ETH wallet = 0xE35120FbF4Fe6d9895cc8a93BD0796b5cB89e776; //Here will come the checksum address of token we got addressOfTokenUsedAsReward = 0x84Ed1B54fa1A26012E6fcA29d55B00BB15bb1deF; tokenReward = token(addressOfTokenUsedAsReward); } bool public started = true; function startSale() public { require (msg.sender == wallet); started = true; } function stopSale() public { require (msg.sender == wallet); started = false; } function changeWallet(address _wallet) public { require (msg.sender == wallet); wallet = _wallet; } function changeTokenReward(address _token) public { require(msg.sender==wallet); tokenReward = token(_token); addressOfTokenUsedAsReward = _token; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } mapping (bytes32 => address) public idToBeneficiary; mapping (bytes32 => uint) public idToWeiAmount; event newOraclizeQuery(string description); function __callback(bytes32 myid, string result) public { require (msg.sender == oraclize_cbAddress()); address beneficiary = idToBeneficiary[myid]; uint weiAmount = idToWeiAmount[myid]; uint ethToCents = parseInt(result,2); uint tokens = weiAmount.mul(ethToCents)/100; tokenReward.transfer(beneficiary, tokens); emit TokenPurchase(beneficiary, beneficiary, weiAmount, tokens); } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); } // send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { wallet.transfer(address(this).balance); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; } function withdrawTokens(uint256 _amount) public { require (msg.sender==wallet); tokenReward.transfer(wallet,_amount); } }
forwardFunds
function forwardFunds() internal { wallet.transfer(address(this).balance); }
// send ether to the fund collection wallet // override to create custom fund forwarding mechanisms
LineComment
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 2949, 3036 ] }
7,945
Crowdsale
Crowdsale.sol
0xd011c319a81085155935ac113115b2ee07d7d425
Solidity
Crowdsale
contract Crowdsale is usingOraclize { using SafeMath for uint256; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward; token tokenReward; // amount of raised money in wei uint256 public weiRaised; /** * 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); constructor () public { //You will change this to your wallet where you need the ETH wallet = 0xE35120FbF4Fe6d9895cc8a93BD0796b5cB89e776; //Here will come the checksum address of token we got addressOfTokenUsedAsReward = 0x84Ed1B54fa1A26012E6fcA29d55B00BB15bb1deF; tokenReward = token(addressOfTokenUsedAsReward); } bool public started = true; function startSale() public { require (msg.sender == wallet); started = true; } function stopSale() public { require (msg.sender == wallet); started = false; } function changeWallet(address _wallet) public { require (msg.sender == wallet); wallet = _wallet; } function changeTokenReward(address _token) public { require(msg.sender==wallet); tokenReward = token(_token); addressOfTokenUsedAsReward = _token; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } mapping (bytes32 => address) public idToBeneficiary; mapping (bytes32 => uint) public idToWeiAmount; event newOraclizeQuery(string description); function __callback(bytes32 myid, string result) public { require (msg.sender == oraclize_cbAddress()); address beneficiary = idToBeneficiary[myid]; uint weiAmount = idToWeiAmount[myid]; uint ethToCents = parseInt(result,2); uint tokens = weiAmount.mul(ethToCents)/100; tokenReward.transfer(beneficiary, tokens); emit TokenPurchase(beneficiary, beneficiary, weiAmount, tokens); } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); } // send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { wallet.transfer(address(this).balance); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; } function withdrawTokens(uint256 _amount) public { require (msg.sender==wallet); tokenReward.transfer(wallet,_amount); } }
validPurchase
function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; }
// @return true if the transaction can buy tokens
LineComment
v0.4.24+commit.e67f0147
bzzr://40403a8be6ee11425a7e6a93fc8b6c99d38febc7ff683510a4ecc32f7f8fc351
{ "func_code_index": [ 3092, 3282 ] }
7,946
OFV2
OFV2.sol
0xb6b309934a16a797a4b92bb6f46427cde1ffc457
Solidity
Token
contract Token { /* This is a slight change to the ERC20 base standard. function totalSupply() constant returns (uint256 supply); is replaced with: uint256 public totalSupply; This automatically creates a getter function for the totalSupply. This is moved to the base contract since public getter functions are not currently recognised as an implementation of the matching abstract function by the compiler. */ /// total amount of tokens //uint256 public totalSupply; function totalSupply() public view returns (uint256 supply); /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) public view returns (uint256 balance); /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) public returns (bool success); /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) public returns (bool success); /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) public view returns (uint256 remaining); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
// Abstract contract for the full ERC 20 Token standard // https://github.com/ethereum/EIPs/issues/20
LineComment
totalSupply
function totalSupply() public view returns (uint256 supply);
//uint256 public totalSupply;
LineComment
v0.4.26+commit.4563c3fc
MIT
bzzr://5d98eb6faef520a5354e5eb2c5027c00db0e4710afaed21c132fe0ecd240cc01
{ "func_code_index": [ 524, 590 ] }
7,947
OFV2
OFV2.sol
0xb6b309934a16a797a4b92bb6f46427cde1ffc457
Solidity
Token
contract Token { /* This is a slight change to the ERC20 base standard. function totalSupply() constant returns (uint256 supply); is replaced with: uint256 public totalSupply; This automatically creates a getter function for the totalSupply. This is moved to the base contract since public getter functions are not currently recognised as an implementation of the matching abstract function by the compiler. */ /// total amount of tokens //uint256 public totalSupply; function totalSupply() public view returns (uint256 supply); /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) public view returns (uint256 balance); /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) public returns (bool success); /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) public returns (bool success); /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) public view returns (uint256 remaining); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
// Abstract contract for the full ERC 20 Token standard // https://github.com/ethereum/EIPs/issues/20
LineComment
balanceOf
function balanceOf(address _owner) public view returns (uint256 balance);
/// @param _owner The address from which the balance will be retrieved /// @return The balance
NatSpecSingleLine
v0.4.26+commit.4563c3fc
MIT
bzzr://5d98eb6faef520a5354e5eb2c5027c00db0e4710afaed21c132fe0ecd240cc01
{ "func_code_index": [ 698, 777 ] }
7,948
OFV2
OFV2.sol
0xb6b309934a16a797a4b92bb6f46427cde1ffc457
Solidity
Token
contract Token { /* This is a slight change to the ERC20 base standard. function totalSupply() constant returns (uint256 supply); is replaced with: uint256 public totalSupply; This automatically creates a getter function for the totalSupply. This is moved to the base contract since public getter functions are not currently recognised as an implementation of the matching abstract function by the compiler. */ /// total amount of tokens //uint256 public totalSupply; function totalSupply() public view returns (uint256 supply); /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) public view returns (uint256 balance); /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) public returns (bool success); /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) public returns (bool success); /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) public view returns (uint256 remaining); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
// Abstract contract for the full ERC 20 Token standard // https://github.com/ethereum/EIPs/issues/20
LineComment
transfer
function transfer(address _to, uint256 _value) public returns (bool success);
/// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not
NatSpecSingleLine
v0.4.26+commit.4563c3fc
MIT
bzzr://5d98eb6faef520a5354e5eb2c5027c00db0e4710afaed21c132fe0ecd240cc01
{ "func_code_index": [ 1014, 1097 ] }
7,949
OFV2
OFV2.sol
0xb6b309934a16a797a4b92bb6f46427cde1ffc457
Solidity
Token
contract Token { /* This is a slight change to the ERC20 base standard. function totalSupply() constant returns (uint256 supply); is replaced with: uint256 public totalSupply; This automatically creates a getter function for the totalSupply. This is moved to the base contract since public getter functions are not currently recognised as an implementation of the matching abstract function by the compiler. */ /// total amount of tokens //uint256 public totalSupply; function totalSupply() public view returns (uint256 supply); /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) public view returns (uint256 balance); /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) public returns (bool success); /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) public returns (bool success); /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) public view returns (uint256 remaining); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
// Abstract contract for the full ERC 20 Token standard // https://github.com/ethereum/EIPs/issues/20
LineComment
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not
NatSpecSingleLine
v0.4.26+commit.4563c3fc
MIT
bzzr://5d98eb6faef520a5354e5eb2c5027c00db0e4710afaed21c132fe0ecd240cc01
{ "func_code_index": [ 1420, 1522 ] }
7,950
OFV2
OFV2.sol
0xb6b309934a16a797a4b92bb6f46427cde1ffc457
Solidity
Token
contract Token { /* This is a slight change to the ERC20 base standard. function totalSupply() constant returns (uint256 supply); is replaced with: uint256 public totalSupply; This automatically creates a getter function for the totalSupply. This is moved to the base contract since public getter functions are not currently recognised as an implementation of the matching abstract function by the compiler. */ /// total amount of tokens //uint256 public totalSupply; function totalSupply() public view returns (uint256 supply); /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) public view returns (uint256 balance); /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) public returns (bool success); /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) public returns (bool success); /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) public view returns (uint256 remaining); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
// Abstract contract for the full ERC 20 Token standard // https://github.com/ethereum/EIPs/issues/20
LineComment
approve
function approve(address _spender, uint256 _value) public returns (bool success);
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not
NatSpecSingleLine
v0.4.26+commit.4563c3fc
MIT
bzzr://5d98eb6faef520a5354e5eb2c5027c00db0e4710afaed21c132fe0ecd240cc01
{ "func_code_index": [ 1806, 1893 ] }
7,951
OFV2
OFV2.sol
0xb6b309934a16a797a4b92bb6f46427cde1ffc457
Solidity
Token
contract Token { /* This is a slight change to the ERC20 base standard. function totalSupply() constant returns (uint256 supply); is replaced with: uint256 public totalSupply; This automatically creates a getter function for the totalSupply. This is moved to the base contract since public getter functions are not currently recognised as an implementation of the matching abstract function by the compiler. */ /// total amount of tokens //uint256 public totalSupply; function totalSupply() public view returns (uint256 supply); /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) public view returns (uint256 balance); /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) public returns (bool success); /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) public returns (bool success); /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) public view returns (uint256 remaining); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
// Abstract contract for the full ERC 20 Token standard // https://github.com/ethereum/EIPs/issues/20
LineComment
allowance
function allowance(address _owner, address _spender) public view returns (uint256 remaining);
/// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent
NatSpecSingleLine
v0.4.26+commit.4563c3fc
MIT
bzzr://5d98eb6faef520a5354e5eb2c5027c00db0e4710afaed21c132fe0ecd240cc01
{ "func_code_index": [ 2101, 2200 ] }
7,952
OFV2
OFV2.sol
0xb6b309934a16a797a4b92bb6f46427cde1ffc457
Solidity
OFV2
contract OFV2 is Token{ using SafeMath for uint256; string public name = "Orb Finance V2"; // Set the name for display purposes string public symbol = "OFV2";// Set the symbol for display purposes uint8 public decimals = 18; uint256 public totalSupply; address public owner; /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; /* Initializes contract with initial supply tokens to the creator of the contract */ constructor() public { totalSupply = 20000 * 10 ** uint256(decimals); // Update total supply balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens owner = msg.sender; } function totalSupply() public view returns (uint256 supply){ return totalSupply; } function balanceOf(address _owner) public view returns (uint256 balance) { return balanceOf[_owner]; } /* Send coins */ function transfer(address _to, uint256 _value) public returns (bool){ require(_to != address(0)); // Prevent transfer to 0x0 address. Use burn() instead require(_value <= balanceOf[msg.sender]); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient emit Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place return true; } /* Allow another contract to spend some tokens in your behalf */ function approve(address _spender, uint256 _value)public returns (bool success) { allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /* A contract attempts to get the coins */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); // Prevent transfer to 0x0 address. Use burn() instead require(_value <= balanceOf[_from]); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows require(_value <= allowance[_from][msg.sender]); // Check allowance balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowance[_owner][_spender]; } }
/// OFV2 token, ERC20 compliant
NatSpecSingleLine
transfer
function transfer(address _to, uint256 _value) public returns (bool){ require(_to != address(0)); // Prevent transfer to 0x0 address. Use burn() instead require(_value <= balanceOf[msg.sender]); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient emit Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place return true; }
/* Send coins */
Comment
v0.4.26+commit.4563c3fc
MIT
bzzr://5d98eb6faef520a5354e5eb2c5027c00db0e4710afaed21c132fe0ecd240cc01
{ "func_code_index": [ 1105, 1872 ] }
7,953
OFV2
OFV2.sol
0xb6b309934a16a797a4b92bb6f46427cde1ffc457
Solidity
OFV2
contract OFV2 is Token{ using SafeMath for uint256; string public name = "Orb Finance V2"; // Set the name for display purposes string public symbol = "OFV2";// Set the symbol for display purposes uint8 public decimals = 18; uint256 public totalSupply; address public owner; /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; /* Initializes contract with initial supply tokens to the creator of the contract */ constructor() public { totalSupply = 20000 * 10 ** uint256(decimals); // Update total supply balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens owner = msg.sender; } function totalSupply() public view returns (uint256 supply){ return totalSupply; } function balanceOf(address _owner) public view returns (uint256 balance) { return balanceOf[_owner]; } /* Send coins */ function transfer(address _to, uint256 _value) public returns (bool){ require(_to != address(0)); // Prevent transfer to 0x0 address. Use burn() instead require(_value <= balanceOf[msg.sender]); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient emit Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place return true; } /* Allow another contract to spend some tokens in your behalf */ function approve(address _spender, uint256 _value)public returns (bool success) { allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /* A contract attempts to get the coins */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); // Prevent transfer to 0x0 address. Use burn() instead require(_value <= balanceOf[_from]); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows require(_value <= allowance[_from][msg.sender]); // Check allowance balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowance[_owner][_spender]; } }
/// OFV2 token, ERC20 compliant
NatSpecSingleLine
approve
function approve(address _spender, uint256 _value)public returns (bool success) { allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; }
/* Allow another contract to spend some tokens in your behalf */
Comment
v0.4.26+commit.4563c3fc
MIT
bzzr://5d98eb6faef520a5354e5eb2c5027c00db0e4710afaed21c132fe0ecd240cc01
{ "func_code_index": [ 1945, 2178 ] }
7,954
OFV2
OFV2.sol
0xb6b309934a16a797a4b92bb6f46427cde1ffc457
Solidity
OFV2
contract OFV2 is Token{ using SafeMath for uint256; string public name = "Orb Finance V2"; // Set the name for display purposes string public symbol = "OFV2";// Set the symbol for display purposes uint8 public decimals = 18; uint256 public totalSupply; address public owner; /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; /* Initializes contract with initial supply tokens to the creator of the contract */ constructor() public { totalSupply = 20000 * 10 ** uint256(decimals); // Update total supply balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens owner = msg.sender; } function totalSupply() public view returns (uint256 supply){ return totalSupply; } function balanceOf(address _owner) public view returns (uint256 balance) { return balanceOf[_owner]; } /* Send coins */ function transfer(address _to, uint256 _value) public returns (bool){ require(_to != address(0)); // Prevent transfer to 0x0 address. Use burn() instead require(_value <= balanceOf[msg.sender]); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient emit Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place return true; } /* Allow another contract to spend some tokens in your behalf */ function approve(address _spender, uint256 _value)public returns (bool success) { allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /* A contract attempts to get the coins */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); // Prevent transfer to 0x0 address. Use burn() instead require(_value <= balanceOf[_from]); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows require(_value <= allowance[_from][msg.sender]); // Check allowance balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowance[_owner][_spender]; } }
/// OFV2 token, ERC20 compliant
NatSpecSingleLine
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); // Prevent transfer to 0x0 address. Use burn() instead require(_value <= balanceOf[_from]); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows require(_value <= allowance[_from][msg.sender]); // Check allowance balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; }
/* A contract attempts to get the coins */
Comment
v0.4.26+commit.4563c3fc
MIT
bzzr://5d98eb6faef520a5354e5eb2c5027c00db0e4710afaed21c132fe0ecd240cc01
{ "func_code_index": [ 2238, 3114 ] }
7,955
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
Ownable
abstract 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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual 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 { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
owner
function owner() public view virtual returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 399, 491 ] }
7,956
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
Ownable
abstract 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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual 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 { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
renounceOwnership
function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); }
/** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 1050, 1149 ] }
7,957
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
Ownable
abstract 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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual 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 { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 1299, 1496 ] }
7,958
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC165
interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
/** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */
NatSpecMultiLine
supportsInterface
function supportsInterface(bytes4 interfaceId) external view returns (bool);
/** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 374, 455 ] }
7,959
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
ERC165
abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
/** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */
NatSpecMultiLine
supportsInterface
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; }
/** * @dev See {IERC165-supportsInterface}. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 103, 265 ] }
7,960
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC721
interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
/** * @dev Required interface of an ERC721 compliant contract. */
NatSpecMultiLine
balanceOf
function balanceOf(address owner) external view returns (uint256 balance);
/** * @dev Returns the number of tokens in ``owner``'s account. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 719, 798 ] }
7,961
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC721
interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
/** * @dev Required interface of an ERC721 compliant contract. */
NatSpecMultiLine
ownerOf
function ownerOf(uint256 tokenId) external view returns (address owner);
/** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 944, 1021 ] }
7,962
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC721
interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
/** * @dev Required interface of an ERC721 compliant contract. */
NatSpecMultiLine
safeTransferFrom
function safeTransferFrom( address from, address to, uint256 tokenId ) external;
/** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 1733, 1850 ] }
7,963
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC721
interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
/** * @dev Required interface of an ERC721 compliant contract. */
NatSpecMultiLine
transferFrom
function transferFrom( address from, address to, uint256 tokenId ) external;
/** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 2376, 2489 ] }
7,964
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC721
interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
/** * @dev Required interface of an ERC721 compliant contract. */
NatSpecMultiLine
approve
function approve(address to, uint256 tokenId) external;
/** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 2962, 3022 ] }
7,965
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC721
interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
/** * @dev Required interface of an ERC721 compliant contract. */
NatSpecMultiLine
getApproved
function getApproved(uint256 tokenId) external view returns (address operator);
/** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 3176, 3260 ] }
7,966
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC721
interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
/** * @dev Required interface of an ERC721 compliant contract. */
NatSpecMultiLine
setApprovalForAll
function setApprovalForAll(address operator, bool _approved) external;
/** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 3587, 3662 ] }
7,967
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC721
interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
/** * @dev Required interface of an ERC721 compliant contract. */
NatSpecMultiLine
isApprovedForAll
function isApprovedForAll(address owner, address operator) external view returns (bool);
/** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 3813, 3906 ] }
7,968
GhettoGrannyClub
@openzeppelin/contracts/access/Ownable.sol
0x2a2efa26af7d5c61b371bce8b4a5006adbef3588
Solidity
IERC721
interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
/** * @dev Required interface of an ERC721 compliant contract. */
NatSpecMultiLine
safeTransferFrom
function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external;
/** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.8.0+commit.c7dfd78e
MIT
ipfs://424e3dba9d144c3a3c9e9b7b8263f195736fcd364dccfa6156e0f1be16d6a030
{ "func_code_index": [ 4483, 4630 ] }
7,969
DegenPass
contracts/DegenPass.sol
0x31b6d1289f96818e79dbb271bf77e8132b86e814
Solidity
DegenPass
contract DegenPass is ERC1155, Ownable, ReentrancyGuard { string public constant name = "Degen Pass"; string public constant symbol = "DEP"; uint private constant maxPasses = 222; uint public passCount = 0; uint private constant passID = 1; bool public isSecondPass = false; bool public isMintOpen = false; bytes32 public merkleRoot = 0xb273f668854fc22a03370abfa36c32b2db9837d8364b79c3b773328809e4bbfa; mapping(address => uint) public whiteListMints; constructor() ERC1155("ipfs://QmdMn3YvP3vGSSKBy5AqCJoEGxY51MC1D388QJ9Ea7p2Gw/metadata.json") {} /** Allows mintlisted members to mint 1 pass during the first pass and allows them to mint 1 more during the second pass. */ function mintListMint(bytes32[] calldata _merkleProof) external nonReentrant{ require(passCount < maxPasses, "Sold out."); require((whiteListMints[msg.sender] < 1) || (isSecondPass && (whiteListMints[msg.sender] < 2)), "Reached mint limit."); require(MerkleProof.verify(_merkleProof, merkleRoot,keccak256(abi.encodePacked(msg.sender))), "Proof invalid."); require(isMintOpen, "Mint not open."); whiteListMints[msg.sender]++; passCount++; _mint(msg.sender, passID, 1, ""); } function setSecondPass() external onlyOwner{ isSecondPass = !isSecondPass; } function setMintOpen() external onlyOwner{ isMintOpen = !isMintOpen; } function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner{ merkleRoot = _merkleRoot; } /** Allows contract owner to mint while still under mint limit. */ function ownerMint(address _to, uint _amount) external onlyOwner { require(passCount + _amount <= maxPasses, "Sold out."); passCount += _amount; _mint(_to, passID, _amount, ""); } function setURI(string memory _uri) external onlyOwner { _setURI(_uri); } function totalSupply() external view returns (uint256) { return passCount; } }
mintListMint
function mintListMint(bytes32[] calldata _merkleProof) external nonReentrant{ require(passCount < maxPasses, "Sold out."); require((whiteListMints[msg.sender] < 1) || (isSecondPass && (whiteListMints[msg.sender] < 2)), "Reached mint limit."); require(MerkleProof.verify(_merkleProof, merkleRoot,keccak256(abi.encodePacked(msg.sender))), "Proof invalid."); require(isMintOpen, "Mint not open."); whiteListMints[msg.sender]++; passCount++; _mint(msg.sender, passID, 1, ""); }
/** Allows mintlisted members to mint 1 pass during the first pass and allows them to mint 1 more during the second pass. */
NatSpecMultiLine
v0.8.12+commit.f00d7308
MIT
ipfs://865fab381d3d28ff78a6f85e1f9ea4b80b1974534177716cbc4b2e8d624a7070
{ "func_code_index": [ 737, 1253 ] }
7,970
DegenPass
contracts/DegenPass.sol
0x31b6d1289f96818e79dbb271bf77e8132b86e814
Solidity
DegenPass
contract DegenPass is ERC1155, Ownable, ReentrancyGuard { string public constant name = "Degen Pass"; string public constant symbol = "DEP"; uint private constant maxPasses = 222; uint public passCount = 0; uint private constant passID = 1; bool public isSecondPass = false; bool public isMintOpen = false; bytes32 public merkleRoot = 0xb273f668854fc22a03370abfa36c32b2db9837d8364b79c3b773328809e4bbfa; mapping(address => uint) public whiteListMints; constructor() ERC1155("ipfs://QmdMn3YvP3vGSSKBy5AqCJoEGxY51MC1D388QJ9Ea7p2Gw/metadata.json") {} /** Allows mintlisted members to mint 1 pass during the first pass and allows them to mint 1 more during the second pass. */ function mintListMint(bytes32[] calldata _merkleProof) external nonReentrant{ require(passCount < maxPasses, "Sold out."); require((whiteListMints[msg.sender] < 1) || (isSecondPass && (whiteListMints[msg.sender] < 2)), "Reached mint limit."); require(MerkleProof.verify(_merkleProof, merkleRoot,keccak256(abi.encodePacked(msg.sender))), "Proof invalid."); require(isMintOpen, "Mint not open."); whiteListMints[msg.sender]++; passCount++; _mint(msg.sender, passID, 1, ""); } function setSecondPass() external onlyOwner{ isSecondPass = !isSecondPass; } function setMintOpen() external onlyOwner{ isMintOpen = !isMintOpen; } function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner{ merkleRoot = _merkleRoot; } /** Allows contract owner to mint while still under mint limit. */ function ownerMint(address _to, uint _amount) external onlyOwner { require(passCount + _amount <= maxPasses, "Sold out."); passCount += _amount; _mint(_to, passID, _amount, ""); } function setURI(string memory _uri) external onlyOwner { _setURI(_uri); } function totalSupply() external view returns (uint256) { return passCount; } }
ownerMint
function ownerMint(address _to, uint _amount) external onlyOwner { require(passCount + _amount <= maxPasses, "Sold out."); passCount += _amount; _mint(_to, passID, _amount, ""); }
/** Allows contract owner to mint while still under mint limit. */
NatSpecMultiLine
v0.8.12+commit.f00d7308
MIT
ipfs://865fab381d3d28ff78a6f85e1f9ea4b80b1974534177716cbc4b2e8d624a7070
{ "func_code_index": [ 1614, 1814 ] }
7,971
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } }
/** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */
NatSpecMultiLine
transfer
function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; }
/** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 268, 659 ] }
7,972
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } }
/** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */
NatSpecMultiLine
balanceOf
function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; }
/** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 865, 977 ] }
7,973
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * 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 */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; }
/** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 401, 853 ] }
7,974
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * 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 */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
approve
function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; }
/** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 1485, 1675 ] }
7,975
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * 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 */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
allowance
function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; }
/** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 1999, 2130 ] }
7,976
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * 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 */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
increaseApproval
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; }
/** * 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 */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 2375, 2639 ] }
7,977
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
Ownable
contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
Ownable
function Ownable() public { owner = msg.sender; }
/** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 261, 321 ] }
7,978
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
Ownable
contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; }
/** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 644, 820 ] }
7,979
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
MintableToken
contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } /** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; MintFinished(); return true; } }
/** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */
NatSpecMultiLine
mint
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; }
/** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 483, 754 ] }
7,980
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
MintableToken
contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } /** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; MintFinished(); return true; } }
/** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */
NatSpecMultiLine
finishMinting
function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; MintFinished(); return true; }
/** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 871, 1013 ] }
7,981
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
YRXToken
contract YRXToken is MintableToken { string public constant name = "Yoritex Token"; string public constant symbol = "YRX"; uint8 public constant decimals = 18; address public crowdsaleAddress; uint256 public constant INITIAL_SUPPLY = 510000000 * 1 ether; modifier nonZeroAddress(address _to) { // Ensures an address is provided require(_to != 0x0); _; } modifier nonZeroAmount(uint _amount) { // Ensures a non-zero amount require(_amount > 0); _; } modifier nonZeroValue() { // Ensures a non-zero value is passed require(msg.value > 0); _; } modifier onlyCrowdsale() { // Ensures only crowdfund can call the function require(msg.sender == crowdsaleAddress); _; } /** * @dev Constructor that gives msg.sender all of existing tokens. */ function YRXToken() public { totalSupply = INITIAL_SUPPLY; balances[msg.sender] = totalSupply; } // ------------------------------------------------- // Sets the crowdsale address, can only be done once // ------------------------------------------------- function setCrowdsaleAddress(address _crowdsaleAddress) external onlyOwner nonZeroAddress(_crowdsaleAddress) returns (bool success){ require(crowdsaleAddress == 0x0); crowdsaleAddress = _crowdsaleAddress; decrementBalance(owner, totalSupply); addToBalance(crowdsaleAddress, totalSupply); Transfer(0x0, _crowdsaleAddress, totalSupply); return true; } // ------------------------------------------------- // Function for the Crowdsale to transfer tokens // ------------------------------------------------- function transferFromCrowdsale(address _to, uint256 _amount) external onlyCrowdsale nonZeroAmount(_amount) nonZeroAddress(_to) returns (bool success) { require(balanceOf(crowdsaleAddress) >= _amount); decrementBalance(crowdsaleAddress, _amount); addToBalance(_to, _amount); Transfer(0x0, _to, _amount); return true; } // ------------------------------------------------- // Adds to balance // ------------------------------------------------- function addToBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].add(_amount); } // ------------------------------------------------- // Removes from balance // ------------------------------------------------- function decrementBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].sub(_amount); } }
/** * @title YRXToken * @dev ERC20 based Token, where all tokens are pre-assigned to the creator. * Note they can later distribute these tokens as they wish using `transfer` and other * `StandardToken` functions. */
NatSpecMultiLine
YRXToken
function YRXToken() public { totalSupply = INITIAL_SUPPLY; balances[msg.sender] = totalSupply; }
/** * @dev Constructor that gives msg.sender all of existing tokens. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 991, 1115 ] }
7,982
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
YRXToken
contract YRXToken is MintableToken { string public constant name = "Yoritex Token"; string public constant symbol = "YRX"; uint8 public constant decimals = 18; address public crowdsaleAddress; uint256 public constant INITIAL_SUPPLY = 510000000 * 1 ether; modifier nonZeroAddress(address _to) { // Ensures an address is provided require(_to != 0x0); _; } modifier nonZeroAmount(uint _amount) { // Ensures a non-zero amount require(_amount > 0); _; } modifier nonZeroValue() { // Ensures a non-zero value is passed require(msg.value > 0); _; } modifier onlyCrowdsale() { // Ensures only crowdfund can call the function require(msg.sender == crowdsaleAddress); _; } /** * @dev Constructor that gives msg.sender all of existing tokens. */ function YRXToken() public { totalSupply = INITIAL_SUPPLY; balances[msg.sender] = totalSupply; } // ------------------------------------------------- // Sets the crowdsale address, can only be done once // ------------------------------------------------- function setCrowdsaleAddress(address _crowdsaleAddress) external onlyOwner nonZeroAddress(_crowdsaleAddress) returns (bool success){ require(crowdsaleAddress == 0x0); crowdsaleAddress = _crowdsaleAddress; decrementBalance(owner, totalSupply); addToBalance(crowdsaleAddress, totalSupply); Transfer(0x0, _crowdsaleAddress, totalSupply); return true; } // ------------------------------------------------- // Function for the Crowdsale to transfer tokens // ------------------------------------------------- function transferFromCrowdsale(address _to, uint256 _amount) external onlyCrowdsale nonZeroAmount(_amount) nonZeroAddress(_to) returns (bool success) { require(balanceOf(crowdsaleAddress) >= _amount); decrementBalance(crowdsaleAddress, _amount); addToBalance(_to, _amount); Transfer(0x0, _to, _amount); return true; } // ------------------------------------------------- // Adds to balance // ------------------------------------------------- function addToBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].add(_amount); } // ------------------------------------------------- // Removes from balance // ------------------------------------------------- function decrementBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].sub(_amount); } }
/** * @title YRXToken * @dev ERC20 based Token, where all tokens are pre-assigned to the creator. * Note they can later distribute these tokens as they wish using `transfer` and other * `StandardToken` functions. */
NatSpecMultiLine
setCrowdsaleAddress
function setCrowdsaleAddress(address _crowdsaleAddress) external onlyOwner nonZeroAddress(_crowdsaleAddress) returns (bool success){ require(crowdsaleAddress == 0x0); crowdsaleAddress = _crowdsaleAddress; decrementBalance(owner, totalSupply); addToBalance(crowdsaleAddress, totalSupply); Transfer(0x0, _crowdsaleAddress, totalSupply); return true; }
// ------------------------------------------------- // Sets the crowdsale address, can only be done once // -------------------------------------------------
LineComment
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 1292, 1705 ] }
7,983
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
YRXToken
contract YRXToken is MintableToken { string public constant name = "Yoritex Token"; string public constant symbol = "YRX"; uint8 public constant decimals = 18; address public crowdsaleAddress; uint256 public constant INITIAL_SUPPLY = 510000000 * 1 ether; modifier nonZeroAddress(address _to) { // Ensures an address is provided require(_to != 0x0); _; } modifier nonZeroAmount(uint _amount) { // Ensures a non-zero amount require(_amount > 0); _; } modifier nonZeroValue() { // Ensures a non-zero value is passed require(msg.value > 0); _; } modifier onlyCrowdsale() { // Ensures only crowdfund can call the function require(msg.sender == crowdsaleAddress); _; } /** * @dev Constructor that gives msg.sender all of existing tokens. */ function YRXToken() public { totalSupply = INITIAL_SUPPLY; balances[msg.sender] = totalSupply; } // ------------------------------------------------- // Sets the crowdsale address, can only be done once // ------------------------------------------------- function setCrowdsaleAddress(address _crowdsaleAddress) external onlyOwner nonZeroAddress(_crowdsaleAddress) returns (bool success){ require(crowdsaleAddress == 0x0); crowdsaleAddress = _crowdsaleAddress; decrementBalance(owner, totalSupply); addToBalance(crowdsaleAddress, totalSupply); Transfer(0x0, _crowdsaleAddress, totalSupply); return true; } // ------------------------------------------------- // Function for the Crowdsale to transfer tokens // ------------------------------------------------- function transferFromCrowdsale(address _to, uint256 _amount) external onlyCrowdsale nonZeroAmount(_amount) nonZeroAddress(_to) returns (bool success) { require(balanceOf(crowdsaleAddress) >= _amount); decrementBalance(crowdsaleAddress, _amount); addToBalance(_to, _amount); Transfer(0x0, _to, _amount); return true; } // ------------------------------------------------- // Adds to balance // ------------------------------------------------- function addToBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].add(_amount); } // ------------------------------------------------- // Removes from balance // ------------------------------------------------- function decrementBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].sub(_amount); } }
/** * @title YRXToken * @dev ERC20 based Token, where all tokens are pre-assigned to the creator. * Note they can later distribute these tokens as they wish using `transfer` and other * `StandardToken` functions. */
NatSpecMultiLine
transferFromCrowdsale
function transferFromCrowdsale(address _to, uint256 _amount) external onlyCrowdsale nonZeroAmount(_amount) nonZeroAddress(_to) returns (bool success) { require(balanceOf(crowdsaleAddress) >= _amount); decrementBalance(crowdsaleAddress, _amount); addToBalance(_to, _amount); Transfer(0x0, _to, _amount); return true; }
// ------------------------------------------------- // Function for the Crowdsale to transfer tokens // -------------------------------------------------
LineComment
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 1878, 2250 ] }
7,984
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
YRXToken
contract YRXToken is MintableToken { string public constant name = "Yoritex Token"; string public constant symbol = "YRX"; uint8 public constant decimals = 18; address public crowdsaleAddress; uint256 public constant INITIAL_SUPPLY = 510000000 * 1 ether; modifier nonZeroAddress(address _to) { // Ensures an address is provided require(_to != 0x0); _; } modifier nonZeroAmount(uint _amount) { // Ensures a non-zero amount require(_amount > 0); _; } modifier nonZeroValue() { // Ensures a non-zero value is passed require(msg.value > 0); _; } modifier onlyCrowdsale() { // Ensures only crowdfund can call the function require(msg.sender == crowdsaleAddress); _; } /** * @dev Constructor that gives msg.sender all of existing tokens. */ function YRXToken() public { totalSupply = INITIAL_SUPPLY; balances[msg.sender] = totalSupply; } // ------------------------------------------------- // Sets the crowdsale address, can only be done once // ------------------------------------------------- function setCrowdsaleAddress(address _crowdsaleAddress) external onlyOwner nonZeroAddress(_crowdsaleAddress) returns (bool success){ require(crowdsaleAddress == 0x0); crowdsaleAddress = _crowdsaleAddress; decrementBalance(owner, totalSupply); addToBalance(crowdsaleAddress, totalSupply); Transfer(0x0, _crowdsaleAddress, totalSupply); return true; } // ------------------------------------------------- // Function for the Crowdsale to transfer tokens // ------------------------------------------------- function transferFromCrowdsale(address _to, uint256 _amount) external onlyCrowdsale nonZeroAmount(_amount) nonZeroAddress(_to) returns (bool success) { require(balanceOf(crowdsaleAddress) >= _amount); decrementBalance(crowdsaleAddress, _amount); addToBalance(_to, _amount); Transfer(0x0, _to, _amount); return true; } // ------------------------------------------------- // Adds to balance // ------------------------------------------------- function addToBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].add(_amount); } // ------------------------------------------------- // Removes from balance // ------------------------------------------------- function decrementBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].sub(_amount); } }
/** * @title YRXToken * @dev ERC20 based Token, where all tokens are pre-assigned to the creator. * Note they can later distribute these tokens as they wish using `transfer` and other * `StandardToken` functions. */
NatSpecMultiLine
addToBalance
function addToBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].add(_amount); }
// ------------------------------------------------- // Adds to balance // -------------------------------------------------
LineComment
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 2393, 2532 ] }
7,985
YRXToken
YRXToken.sol
0x0c36d834a50e9149ff38ea6221cfaeabf607d57d
Solidity
YRXToken
contract YRXToken is MintableToken { string public constant name = "Yoritex Token"; string public constant symbol = "YRX"; uint8 public constant decimals = 18; address public crowdsaleAddress; uint256 public constant INITIAL_SUPPLY = 510000000 * 1 ether; modifier nonZeroAddress(address _to) { // Ensures an address is provided require(_to != 0x0); _; } modifier nonZeroAmount(uint _amount) { // Ensures a non-zero amount require(_amount > 0); _; } modifier nonZeroValue() { // Ensures a non-zero value is passed require(msg.value > 0); _; } modifier onlyCrowdsale() { // Ensures only crowdfund can call the function require(msg.sender == crowdsaleAddress); _; } /** * @dev Constructor that gives msg.sender all of existing tokens. */ function YRXToken() public { totalSupply = INITIAL_SUPPLY; balances[msg.sender] = totalSupply; } // ------------------------------------------------- // Sets the crowdsale address, can only be done once // ------------------------------------------------- function setCrowdsaleAddress(address _crowdsaleAddress) external onlyOwner nonZeroAddress(_crowdsaleAddress) returns (bool success){ require(crowdsaleAddress == 0x0); crowdsaleAddress = _crowdsaleAddress; decrementBalance(owner, totalSupply); addToBalance(crowdsaleAddress, totalSupply); Transfer(0x0, _crowdsaleAddress, totalSupply); return true; } // ------------------------------------------------- // Function for the Crowdsale to transfer tokens // ------------------------------------------------- function transferFromCrowdsale(address _to, uint256 _amount) external onlyCrowdsale nonZeroAmount(_amount) nonZeroAddress(_to) returns (bool success) { require(balanceOf(crowdsaleAddress) >= _amount); decrementBalance(crowdsaleAddress, _amount); addToBalance(_to, _amount); Transfer(0x0, _to, _amount); return true; } // ------------------------------------------------- // Adds to balance // ------------------------------------------------- function addToBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].add(_amount); } // ------------------------------------------------- // Removes from balance // ------------------------------------------------- function decrementBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].sub(_amount); } }
/** * @title YRXToken * @dev ERC20 based Token, where all tokens are pre-assigned to the creator. * Note they can later distribute these tokens as they wish using `transfer` and other * `StandardToken` functions. */
NatSpecMultiLine
decrementBalance
function decrementBalance(address _address, uint _amount) internal { balances[_address] = balances[_address].sub(_amount); }
// ------------------------------------------------- // Removes from balance // -------------------------------------------------
LineComment
v0.4.18+commit.9cf6e910
bzzr://a27a0f711955159ad9c4bc45ea157ace8a419e7948057a6b6b07df3953440255
{ "func_code_index": [ 2680, 2823 ] }
7,986
TNT
TNT.sol
0x23221fe28dadf788c7c59d0367bafef3b1607344
Solidity
TNT
contract TNT { /* Public variables of the token */ string public standard = 'Token 0.1'; string public name; string public symbol; uint8 public decimals; uint256 public initialSupply; uint256 public totalSupply; /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; /* Initializes contract with initial supply tokens to the creator of the contract */ function TNT() { initialSupply = 100000000; name ="TNT"; decimals = 0; symbol = "P"; balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens totalSupply = initialSupply; // Update total supply } /* Send coins */ function transfer(address _to, uint256 _value) { if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows balanceOf[msg.sender] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient } /* This unnamed function is called whenever someone tries to send ether to it */ function () { throw; // Prevents accidental sending of ether } }
TNT
function TNT() { initialSupply = 100000000; name ="TNT"; decimals = 0; symbol = "P"; balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens totalSupply = initialSupply; // Update total supply }
/* Initializes contract with initial supply tokens to the creator of the contract */
Comment
v0.4.19+commit.c4cbbb05
bzzr://6005f2b24e487fa37434c61f4e26e4bb23ec61e3c1235574b77416f8cf9691b5
{ "func_code_index": [ 522, 890 ] }
7,987
TNT
TNT.sol
0x23221fe28dadf788c7c59d0367bafef3b1607344
Solidity
TNT
contract TNT { /* Public variables of the token */ string public standard = 'Token 0.1'; string public name; string public symbol; uint8 public decimals; uint256 public initialSupply; uint256 public totalSupply; /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; /* Initializes contract with initial supply tokens to the creator of the contract */ function TNT() { initialSupply = 100000000; name ="TNT"; decimals = 0; symbol = "P"; balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens totalSupply = initialSupply; // Update total supply } /* Send coins */ function transfer(address _to, uint256 _value) { if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows balanceOf[msg.sender] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient } /* This unnamed function is called whenever someone tries to send ether to it */ function () { throw; // Prevents accidental sending of ether } }
transfer
function transfer(address _to, uint256 _value) { if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows balanceOf[msg.sender] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient }
/* Send coins */
Comment
v0.4.19+commit.c4cbbb05
bzzr://6005f2b24e487fa37434c61f4e26e4bb23ec61e3c1235574b77416f8cf9691b5
{ "func_code_index": [ 915, 1349 ] }
7,988
TNT
TNT.sol
0x23221fe28dadf788c7c59d0367bafef3b1607344
Solidity
TNT
contract TNT { /* Public variables of the token */ string public standard = 'Token 0.1'; string public name; string public symbol; uint8 public decimals; uint256 public initialSupply; uint256 public totalSupply; /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; /* Initializes contract with initial supply tokens to the creator of the contract */ function TNT() { initialSupply = 100000000; name ="TNT"; decimals = 0; symbol = "P"; balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens totalSupply = initialSupply; // Update total supply } /* Send coins */ function transfer(address _to, uint256 _value) { if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows balanceOf[msg.sender] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient } /* This unnamed function is called whenever someone tries to send ether to it */ function () { throw; // Prevents accidental sending of ether } }
function () { throw; // Prevents accidental sending of ether }
/* This unnamed function is called whenever someone tries to send ether to it */
Comment
v0.4.19+commit.c4cbbb05
bzzr://6005f2b24e487fa37434c61f4e26e4bb23ec61e3c1235574b77416f8cf9691b5
{ "func_code_index": [ 1460, 1545 ] }
7,989
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
_baseURI
function _baseURI() internal view virtual override returns (string memory) { return metadataURI; }
// === URI ===
LineComment
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 2105, 2219 ] }
7,990
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
setBaseURI
function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; }
/// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 2332, 2426 ] }
7,991
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
pauseSale
function pauseSale() external onlyOwner { state = SaleState.Paused; }
/// Pause sale.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 2475, 2560 ] }
7,992
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
startPresale
function startPresale() external onlyOwner { state = SaleState.Presale; }
/// Start Presale, if paused.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 3256, 3345 ] }
7,993
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
startCollectorsSale
function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; }
/// Start Collectors sale, if paused.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 4066, 4165 ] }
7,994
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
startSale
function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; }
/// Start Sale, if paused.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 4198, 4335 ] }
7,995
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
setPrice
function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; }
// === Minting ===
LineComment
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 4361, 4520 ] }
7,996
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
mintSuperRock
function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } }
/// Mints SuperRocks
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 4547, 5671 ] }
7,997
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
setProvenanceHash
function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; }
/// Set provenance hash once it's calculated.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 7786, 8024 ] }
7,998
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
setRandomStartingIndex
function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } }
/// Set the random starting index for the collection.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 8371, 9046 ] }
7,999
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
emergencySetRandomStartingIndexBlock
function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; }
/// Set the random starting index block for the collection.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 9112, 9308 ] }
8,000
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
reserveTeamRocks
function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; }
/// Set some tokens aside for marketing.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 9384, 9921 ] }
8,001
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
withdrawAll
function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); }
/// Split the balance to all wallets.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 10346, 11343 ] }
8,002
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
isApprovedForAll
function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); }
/// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 11664, 12100 ] }
8,003
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
setProxyRegistryAddress
function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; }
/// Update the registry address in case of an error.
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 12159, 12325 ] }
8,004
SuperRocks
contracts/SuperRocks.sol
0xf66bb6beebd5942d71e5e64e6008ef722f90a050
Solidity
SuperRocks
contract SuperRocks is ERC721Enumerable, IERC2981, Ownable, ReentrancyGuard { using Strings for uint256; enum SaleState { Paused, Collectors, Presale, Sale } SaleState public state; // Provenance string public provenanceHash = ""; uint256 public randomStartingIndexBlock; uint256 public randomStartingIndex; bool public isProvenanceHashFrozen = false; // Presale lists mapping(address => uint8) private presaleList; mapping(address => uint8) private collectorsList; // Prices uint256 public price = 0.03 ether; // Limits uint256 public constant MAX_ROCKS = 8888; uint256 public constant TEAM_RESERVED_ROCKS_LIMIT = 100; uint8 public constant TRANSACTION_MINT_LIMIT = 10; uint8 public constant COLLECTORS_MINT_LIMIT = 1; uint256 private teamSupply = 0; // Metadata uint256 public revealTimeStamp; string public metadataURI; address public proxyRegistryAddress; // Team // Dev1, Dev2 address private dev1 = 0x740EBD582c773C8EE050D053B1092b0075367F4A; address private dev2 = 0x9d9685eF83fF9bFCeDB6F039116665f14c469745; // Community, Marketing, Expenses, Creator address[] private teamWallets = [ 0x41cF69033470843fe53A10a36678348EaF474033, 0x436736639eaACdC344Db6aAe2679858BF419D748, 0xC3A289a4A4576DA6DA2414B70df7efb367Ea8C89, 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B ]; address public royaltyAddress = 0x5dfD9Ebaf998EDc9d85291e1AF4b2ebF7e2Aae4B; uint256 public royaltyBasis = 500; // 5% event Minted(address owner, uint256 tokenId); constructor( string memory name, string memory symbol, string memory _placeholderCID, address _proxyRegistryAddress ) ERC721(name, symbol) { metadataURI = _placeholderCID; state = SaleState.Paused; proxyRegistryAddress = _proxyRegistryAddress; } modifier whenSalePaused() { require(state == SaleState.Paused, "SuperRocks: Sale in progress"); _; } // === URI === function _baseURI() internal view virtual override returns (string memory) { return metadataURI; } /// Set the base UIR for this collection. /// @param uri the new uri. /// @dev update the baseURI. function setBaseURI(string memory uri) public onlyOwner { metadataURI = uri; } // === Sale State === /// Pause sale. function pauseSale() external onlyOwner { state = SaleState.Paused; } function addToPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { presaleList[addresses[i]] = TRANSACTION_MINT_LIMIT; } } function deleteFromPresaleList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { presaleList[addresses[i]] = 0; } } function presaleListCount(address _address) public view returns (uint8) { return presaleList[_address]; } /// Start Presale, if paused. function startPresale() external onlyOwner { state = SaleState.Presale; } function addToCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { uint256 length = addresses.length; for (uint256 i = 0; i < length; i++) { collectorsList[addresses[i]] = COLLECTORS_MINT_LIMIT; } } function deleteFromCollectorsList(address[] memory addresses) external onlyOwner whenSalePaused { for (uint256 i = 0; i < addresses.length; i++) { collectorsList[addresses[i]] = 0; } } function collectorsListCount(address _address) public view returns (uint8) { return collectorsList[_address]; } /// Start Collectors sale, if paused. function startCollectorsSale() external onlyOwner { state = SaleState.Collectors; } /// Start Sale, if paused. function startSale(uint256 timeStamp) external onlyOwner { state = SaleState.Sale; revealTimeStamp = timeStamp; } // === Minting === function setPrice(uint256 _price) public onlyOwner whenSalePaused { require(_price > 0, "SuperRocks: Invalid price"); price = _price; } /// Mints SuperRocks function mintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Sale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } // - randomStartingIndexBlock is not already set // - the last token in supply or // - the first token to be sold after the end of the metadata reveal date if ( randomStartingIndexBlock == 0 && (totalSupply() == MAX_ROCKS || block.timestamp >= revealTimeStamp) ) { randomStartingIndexBlock = block.number; } } function presaleMintSuperRock(uint8 numberOfTokens) public payable nonReentrant { require(state == SaleState.Presale, "SuperRocks: Minting not allowed"); uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( numberOfTokens <= TRANSACTION_MINT_LIMIT, "SuperRocks: Max 10 tokens" ); require( price * numberOfTokens <= msg.value, "SuperRocks: Not enough ETH" ); require(presaleList[msg.sender] > 0, "SuperRocks: Not in presale list"); require( presaleList[msg.sender] - numberOfTokens >= 0, "SuperRocks: Reached mint limit" ); presaleList[msg.sender] -= numberOfTokens; for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); emit Minted(msg.sender, supply + i); } } function claimSuperRock() public nonReentrant { require( state == SaleState.Collectors, "SuperRocks: Minting not allowed" ); uint256 supply = totalSupply(); require(supply + 1 <= MAX_ROCKS, "SuperRocks: More than max supply"); require(collectorsList[msg.sender] > 0, "SuperRocks: Not in the list"); require( collectorsList[msg.sender] - 1 >= 0, "SuperRocks: Reached claim limit" ); collectorsList[msg.sender] -= 1; _safeMint(msg.sender, supply); emit Minted(msg.sender, supply); } function walletOfOwner(address _owner) external view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokensIDs = new uint256[](tokenCount); for (uint256 i = 0; i < tokenCount; i++) { tokensIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokensIDs; } // === Provenance === /// Set provenance hash once it's calculated. function setProvenanceHash(string memory provenance) public onlyOwner { require( isProvenanceHashFrozen == false, "SuperRocks: Provenance is frozen" ); provenanceHash = provenance; } function freezeProvenanceHash() public onlyOwner { isProvenanceHashFrozen = true; } function calculateStartingIndex(uint256 blockNumber) internal view returns (uint256) { return uint256(blockhash(blockNumber)) % MAX_ROCKS; } /// Set the random starting index for the collection. function setRandomStartingIndex() public { require(randomStartingIndex == 0, "SuperRocks: index is set"); require(randomStartingIndexBlock != 0, "SuperRocks: block must be set"); randomStartingIndex = calculateStartingIndex(randomStartingIndexBlock); // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes) if (block.number - randomStartingIndexBlock > 255) { randomStartingIndex = calculateStartingIndex(block.number - 1); } // Prevent default sequence if (randomStartingIndex == 0) { randomStartingIndex++; } } /// Set the random starting index block for the collection. function emergencySetRandomStartingIndexBlock() public onlyOwner { require(randomStartingIndex == 0, "SuperRocks: index is set"); randomStartingIndexBlock = block.number; } // === Team Helpers === /// Set some tokens aside for marketing. function reserveTeamRocks(uint8 numberOfTokens) public onlyOwner { uint256 supply = totalSupply(); require( supply + numberOfTokens <= MAX_ROCKS, "SuperRocks: More than max supply" ); require( teamSupply + numberOfTokens <= TEAM_RESERVED_ROCKS_LIMIT, "SuperRocks: Reached team supply" ); for (uint256 i = 0; i < numberOfTokens; i++) { _safeMint(msg.sender, supply + i); } teamSupply += numberOfTokens; } function setTeamWallets(address[] memory _teamWallets) public onlyOwner { require(_teamWallets.length == 4, "SuperRocks: Needs 4 wallets"); teamWallets = [ _teamWallets[0], _teamWallets[1], _teamWallets[2], _teamWallets[3] ]; } event SplitsWithdrawn(address[6] _addresses, uint256[6] _amounts); /// Split the balance to all wallets. function withdrawAll() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "SuperRocks: Nothing to split"); uint256 split1 = (balance * 15) / 100; _widthdraw(dev1, split1); uint256 split2 = (balance * 15) / 100; _widthdraw(dev2, split2); uint256 split3 = (balance * 10) / 100; _widthdraw(teamWallets[0], split3); uint256 split4 = (balance * 10) / 100; _widthdraw(teamWallets[1], split4); uint256 split5 = (balance * 5) / 100; _widthdraw(teamWallets[2], split5); uint256 split6 = address(this).balance; _widthdraw(teamWallets[3], split6); emit SplitsWithdrawn( [ dev1, dev2, teamWallets[0], teamWallets[1], teamWallets[2], teamWallets[3] ], [split1, split2, split3, split4, split5, split6] ); } function _widthdraw(address to, uint256 _amount) private { (bool success, ) = to.call{value: _amount}(""); require(success, "SuperRocks: Transfer failed"); } // === OpenSea Proxy === /// Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. function isApprovedForAll(address owner, address operator) public view override returns (bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /// Update the registry address in case of an error. function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } // === Royalties === function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; } function royaltyInfo(uint256, uint256 salePrice) external view override returns (address receiver, uint256 royaltyAmount) { return (royaltyAddress, (salePrice * royaltyBasis) / 10000); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, IERC165) returns (bool) { return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId)); } }
/** * @title SuperRocks contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */
NatSpecMultiLine
setRoyalty
function setRoyalty(address _royaltyAddress, uint256 _royaltyBasis) public onlyOwner { royaltyAddress = _royaltyAddress; royaltyBasis = _royaltyBasis; }
// === Royalties ===
LineComment
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 12353, 12549 ] }
8,005
CosmicLabs
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/Math.sol
0x96316355c44be69414756d6706c61e61aecbd5f3
Solidity
Math
library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a / b + (a % b == 0 ? 0 : 1); } }
/** * @dev Standard math utilities missing in the Solidity language. */
NatSpecMultiLine
max
function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; }
/** * @dev Returns the largest of two numbers. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
Unlicense
ipfs://a10847e6cf20c66bce0dfc9f136d780180511ecda3b9a86ce938006f46eec852
{ "func_code_index": [ 83, 195 ] }
8,006