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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
UniswapV3Product | contracts/interface/UniswapV3/IUniswapV3Pool.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | IUniswapV3PoolActions | interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
} | /// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone | NatSpecSingleLine | initialize | function initialize(uint160 sqrtPriceX96) external;
| /// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 | NatSpecSingleLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
245,
300
]
} | 9,607 |
||
UniswapV3Product | contracts/interface/UniswapV3/IUniswapV3Pool.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | IUniswapV3PoolActions | interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
} | /// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone | NatSpecSingleLine | mint | function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
| /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback | NatSpecSingleLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
1336,
1542
]
} | 9,608 |
||
UniswapV3Product | contracts/interface/UniswapV3/IUniswapV3Pool.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | IUniswapV3PoolActions | interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
} | /// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone | NatSpecSingleLine | collect | function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
| /// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1 | NatSpecSingleLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
2602,
2826
]
} | 9,609 |
||
UniswapV3Product | contracts/interface/UniswapV3/IUniswapV3Pool.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | IUniswapV3PoolActions | interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
} | /// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone | NatSpecSingleLine | burn | function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
| /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient | NatSpecSingleLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
3464,
3614
]
} | 9,610 |
||
UniswapV3Product | contracts/interface/UniswapV3/IUniswapV3Pool.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | IUniswapV3PoolActions | interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
} | /// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone | NatSpecSingleLine | swap | function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
| /// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive | NatSpecSingleLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
4636,
4858
]
} | 9,611 |
||
UniswapV3Product | contracts/interface/UniswapV3/IUniswapV3Pool.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | IUniswapV3PoolActions | interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
} | /// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone | NatSpecSingleLine | flash | function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
| /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback | NatSpecSingleLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
5522,
5662
]
} | 9,612 |
||
UniswapV3Product | contracts/interface/UniswapV3/IUniswapV3Pool.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | IUniswapV3PoolActions | interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
} | /// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone | NatSpecSingleLine | increaseObservationCardinalityNext | function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
| /// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store | NatSpecSingleLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
6036,
6128
]
} | 9,613 |
||
UniswapV3Product | contracts/interface/UniswapV3/IUniswapV3Pool.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | IUniswapV3PoolOwnerActions | interface IUniswapV3PoolOwnerActions {
/// @notice Set the denominator of the protocol's % share of the fees
/// @param feeProtocol0 new protocol fee for token0 of the pool
/// @param feeProtocol1 new protocol fee for token1 of the pool
function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;
/// @notice Collect the protocol fee accrued to the pool
/// @param recipient The address to which collected protocol fees should be sent
/// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
/// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
/// @return amount0 The protocol fee collected in token0
/// @return amount1 The protocol fee collected in token1
function collectProtocol(
address recipient,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
} | /// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner | NatSpecSingleLine | setFeeProtocol | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;
| /// @notice Set the denominator of the protocol's % share of the fees
/// @param feeProtocol0 new protocol fee for token0 of the pool
/// @param feeProtocol1 new protocol fee for token1 of the pool | NatSpecSingleLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
249,
326
]
} | 9,614 |
||
UniswapV3Product | contracts/interface/UniswapV3/IUniswapV3Pool.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | IUniswapV3PoolOwnerActions | interface IUniswapV3PoolOwnerActions {
/// @notice Set the denominator of the protocol's % share of the fees
/// @param feeProtocol0 new protocol fee for token0 of the pool
/// @param feeProtocol1 new protocol fee for token1 of the pool
function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;
/// @notice Collect the protocol fee accrued to the pool
/// @param recipient The address to which collected protocol fees should be sent
/// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
/// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
/// @return amount0 The protocol fee collected in token0
/// @return amount1 The protocol fee collected in token1
function collectProtocol(
address recipient,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
} | /// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner | NatSpecSingleLine | collectProtocol | function collectProtocol(
address recipient,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
| /// @notice Collect the protocol fee accrued to the pool
/// @param recipient The address to which collected protocol fees should be sent
/// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
/// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
/// @return amount0 The protocol fee collected in token0
/// @return amount1 The protocol fee collected in token1 | NatSpecSingleLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
816,
998
]
} | 9,615 |
||
UniswapV3Product | contracts/products/UniswapV3Product.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | UniswapV3Product | contract UniswapV3Product is BaseProduct {
IUniswapV3Factory internal _uniV3Factory;
/**
* @notice Constructs the UniswapV3Product.
* @param governance_ The address of the [governor](/docs/protocol/governance).
* @param policyManager_ The [`PolicyManager`](../PolicyManager) contract.
* @param registry_ The [`Registry`](../Registry) contract.
* @param uniV3Factory_ The UniswapV3Product Factory.
* @param minPeriod_ The minimum policy period in blocks to purchase a **policy**.
* @param maxPeriod_ The maximum policy period in blocks to purchase a **policy**.
*/
constructor (
address governance_,
IPolicyManager policyManager_,
IRegistry registry_,
address uniV3Factory_,
uint40 minPeriod_,
uint40 maxPeriod_
) BaseProduct(
governance_,
policyManager_,
registry_,
uniV3Factory_,
minPeriod_,
maxPeriod_,
"Solace.fi-UniswapV3Product",
"1"
) {
_uniV3Factory = IUniswapV3Factory(uniV3Factory_);
_SUBMIT_CLAIM_TYPEHASH = keccak256("UniswapV3ProductSubmitClaim(uint256 policyID,address claimant,uint256 amountOut,uint256 deadline)");
_productName = "UniswapV3";
}
/**
* @notice Uniswap V2 Factory.
* @return uniV3Factory_ The factory.
*/
function uniV2Factory() external view returns (address uniV3Factory_) {
return address(_uniV3Factory);
}
/**
* @notice Determines if the byte encoded description of a position(s) is valid.
* The description will only make sense in context of the product.
* @dev This function should be overwritten in inheriting Product contracts.
* If invalid, return false if possible. Reverting is also acceptable.
* @param positionDescription The description to validate.
* @return isValid True if is valid.
*/
function isValidPositionDescription(bytes memory positionDescription) public view virtual override returns (bool isValid) {
// check length
// solhint-disable-next-line var-name-mixedcase
uint256 ADDRESS_SIZE = 20;
// must be concatenation of one or more addresses
if(positionDescription.length == 0 || positionDescription.length % ADDRESS_SIZE != 0) return false;
// check all addresses in list
for(uint256 offset = 0; offset < positionDescription.length; offset += ADDRESS_SIZE) {
// get next address
address positionContract;
// solhint-disable-next-line no-inline-assembly
assembly {
positionContract := div(mload(add(add(positionDescription, 0x20), offset)), 0x1000000000000000000000000)
}
// must be UniswapV3 Pool
IUniswapV3Pool uniswapV3Pool = IUniswapV3Pool(positionContract);
address pool = _uniV3Factory.getPool(uniswapV3Pool.token0(), uniswapV3Pool.token1(), uniswapV3Pool.fee());
if (pool != address(uniswapV3Pool)) return false;
}
return true;
}
/***************************************
GOVERNANCE FUNCTIONS
***************************************/
/**
* @notice Changes the covered platform.
* Can only be called by the current [**governor**](/docs/protocol/governance).
* @dev Use this if the the protocol changes their registry but keeps the children contracts.
* A new version of the protocol will likely require a new Product.
* @param uniV3Factory_ The new Address Provider.
*/
function setCoveredPlatform(address uniV3Factory_) public override {
super.setCoveredPlatform(uniV3Factory_);
_uniV3Factory = IUniswapV3Factory(uniV3Factory_);
}
} | /**
* @title UniswapV3Product
* @author solace.fi
* @notice The **UniswapV3Product** can be used to purchase coverage for **UniswapV3 LP** positions.
*/ | NatSpecMultiLine | uniV2Factory | function uniV2Factory() external view returns (address uniV3Factory_) {
return address(_uniV3Factory);
}
| /**
* @notice Uniswap V2 Factory.
* @return uniV3Factory_ The factory.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
1363,
1483
]
} | 9,616 |
||
UniswapV3Product | contracts/products/UniswapV3Product.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | UniswapV3Product | contract UniswapV3Product is BaseProduct {
IUniswapV3Factory internal _uniV3Factory;
/**
* @notice Constructs the UniswapV3Product.
* @param governance_ The address of the [governor](/docs/protocol/governance).
* @param policyManager_ The [`PolicyManager`](../PolicyManager) contract.
* @param registry_ The [`Registry`](../Registry) contract.
* @param uniV3Factory_ The UniswapV3Product Factory.
* @param minPeriod_ The minimum policy period in blocks to purchase a **policy**.
* @param maxPeriod_ The maximum policy period in blocks to purchase a **policy**.
*/
constructor (
address governance_,
IPolicyManager policyManager_,
IRegistry registry_,
address uniV3Factory_,
uint40 minPeriod_,
uint40 maxPeriod_
) BaseProduct(
governance_,
policyManager_,
registry_,
uniV3Factory_,
minPeriod_,
maxPeriod_,
"Solace.fi-UniswapV3Product",
"1"
) {
_uniV3Factory = IUniswapV3Factory(uniV3Factory_);
_SUBMIT_CLAIM_TYPEHASH = keccak256("UniswapV3ProductSubmitClaim(uint256 policyID,address claimant,uint256 amountOut,uint256 deadline)");
_productName = "UniswapV3";
}
/**
* @notice Uniswap V2 Factory.
* @return uniV3Factory_ The factory.
*/
function uniV2Factory() external view returns (address uniV3Factory_) {
return address(_uniV3Factory);
}
/**
* @notice Determines if the byte encoded description of a position(s) is valid.
* The description will only make sense in context of the product.
* @dev This function should be overwritten in inheriting Product contracts.
* If invalid, return false if possible. Reverting is also acceptable.
* @param positionDescription The description to validate.
* @return isValid True if is valid.
*/
function isValidPositionDescription(bytes memory positionDescription) public view virtual override returns (bool isValid) {
// check length
// solhint-disable-next-line var-name-mixedcase
uint256 ADDRESS_SIZE = 20;
// must be concatenation of one or more addresses
if(positionDescription.length == 0 || positionDescription.length % ADDRESS_SIZE != 0) return false;
// check all addresses in list
for(uint256 offset = 0; offset < positionDescription.length; offset += ADDRESS_SIZE) {
// get next address
address positionContract;
// solhint-disable-next-line no-inline-assembly
assembly {
positionContract := div(mload(add(add(positionDescription, 0x20), offset)), 0x1000000000000000000000000)
}
// must be UniswapV3 Pool
IUniswapV3Pool uniswapV3Pool = IUniswapV3Pool(positionContract);
address pool = _uniV3Factory.getPool(uniswapV3Pool.token0(), uniswapV3Pool.token1(), uniswapV3Pool.fee());
if (pool != address(uniswapV3Pool)) return false;
}
return true;
}
/***************************************
GOVERNANCE FUNCTIONS
***************************************/
/**
* @notice Changes the covered platform.
* Can only be called by the current [**governor**](/docs/protocol/governance).
* @dev Use this if the the protocol changes their registry but keeps the children contracts.
* A new version of the protocol will likely require a new Product.
* @param uniV3Factory_ The new Address Provider.
*/
function setCoveredPlatform(address uniV3Factory_) public override {
super.setCoveredPlatform(uniV3Factory_);
_uniV3Factory = IUniswapV3Factory(uniV3Factory_);
}
} | /**
* @title UniswapV3Product
* @author solace.fi
* @notice The **UniswapV3Product** can be used to purchase coverage for **UniswapV3 LP** positions.
*/ | NatSpecMultiLine | isValidPositionDescription | function isValidPositionDescription(bytes memory positionDescription) public view virtual override returns (bool isValid) {
// check length
// solhint-disable-next-line var-name-mixedcase
uint256 ADDRESS_SIZE = 20;
// must be concatenation of one or more addresses
if(positionDescription.length == 0 || positionDescription.length % ADDRESS_SIZE != 0) return false;
// check all addresses in list
for(uint256 offset = 0; offset < positionDescription.length; offset += ADDRESS_SIZE) {
// get next address
address positionContract;
// solhint-disable-next-line no-inline-assembly
assembly {
positionContract := div(mload(add(add(positionDescription, 0x20), offset)), 0x1000000000000000000000000)
}
// must be UniswapV3 Pool
IUniswapV3Pool uniswapV3Pool = IUniswapV3Pool(positionContract);
address pool = _uniV3Factory.getPool(uniswapV3Pool.token0(), uniswapV3Pool.token1(), uniswapV3Pool.fee());
if (pool != address(uniswapV3Pool)) return false;
}
return true;
}
| /**
* @notice Determines if the byte encoded description of a position(s) is valid.
* The description will only make sense in context of the product.
* @dev This function should be overwritten in inheriting Product contracts.
* If invalid, return false if possible. Reverting is also acceptable.
* @param positionDescription The description to validate.
* @return isValid True if is valid.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
1917,
3080
]
} | 9,617 |
||
UniswapV3Product | contracts/products/UniswapV3Product.sol | 0x501ace6c657a9b53b320780068fd99894d5795cb | Solidity | UniswapV3Product | contract UniswapV3Product is BaseProduct {
IUniswapV3Factory internal _uniV3Factory;
/**
* @notice Constructs the UniswapV3Product.
* @param governance_ The address of the [governor](/docs/protocol/governance).
* @param policyManager_ The [`PolicyManager`](../PolicyManager) contract.
* @param registry_ The [`Registry`](../Registry) contract.
* @param uniV3Factory_ The UniswapV3Product Factory.
* @param minPeriod_ The minimum policy period in blocks to purchase a **policy**.
* @param maxPeriod_ The maximum policy period in blocks to purchase a **policy**.
*/
constructor (
address governance_,
IPolicyManager policyManager_,
IRegistry registry_,
address uniV3Factory_,
uint40 minPeriod_,
uint40 maxPeriod_
) BaseProduct(
governance_,
policyManager_,
registry_,
uniV3Factory_,
minPeriod_,
maxPeriod_,
"Solace.fi-UniswapV3Product",
"1"
) {
_uniV3Factory = IUniswapV3Factory(uniV3Factory_);
_SUBMIT_CLAIM_TYPEHASH = keccak256("UniswapV3ProductSubmitClaim(uint256 policyID,address claimant,uint256 amountOut,uint256 deadline)");
_productName = "UniswapV3";
}
/**
* @notice Uniswap V2 Factory.
* @return uniV3Factory_ The factory.
*/
function uniV2Factory() external view returns (address uniV3Factory_) {
return address(_uniV3Factory);
}
/**
* @notice Determines if the byte encoded description of a position(s) is valid.
* The description will only make sense in context of the product.
* @dev This function should be overwritten in inheriting Product contracts.
* If invalid, return false if possible. Reverting is also acceptable.
* @param positionDescription The description to validate.
* @return isValid True if is valid.
*/
function isValidPositionDescription(bytes memory positionDescription) public view virtual override returns (bool isValid) {
// check length
// solhint-disable-next-line var-name-mixedcase
uint256 ADDRESS_SIZE = 20;
// must be concatenation of one or more addresses
if(positionDescription.length == 0 || positionDescription.length % ADDRESS_SIZE != 0) return false;
// check all addresses in list
for(uint256 offset = 0; offset < positionDescription.length; offset += ADDRESS_SIZE) {
// get next address
address positionContract;
// solhint-disable-next-line no-inline-assembly
assembly {
positionContract := div(mload(add(add(positionDescription, 0x20), offset)), 0x1000000000000000000000000)
}
// must be UniswapV3 Pool
IUniswapV3Pool uniswapV3Pool = IUniswapV3Pool(positionContract);
address pool = _uniV3Factory.getPool(uniswapV3Pool.token0(), uniswapV3Pool.token1(), uniswapV3Pool.fee());
if (pool != address(uniswapV3Pool)) return false;
}
return true;
}
/***************************************
GOVERNANCE FUNCTIONS
***************************************/
/**
* @notice Changes the covered platform.
* Can only be called by the current [**governor**](/docs/protocol/governance).
* @dev Use this if the the protocol changes their registry but keeps the children contracts.
* A new version of the protocol will likely require a new Product.
* @param uniV3Factory_ The new Address Provider.
*/
function setCoveredPlatform(address uniV3Factory_) public override {
super.setCoveredPlatform(uniV3Factory_);
_uniV3Factory = IUniswapV3Factory(uniV3Factory_);
}
} | /**
* @title UniswapV3Product
* @author solace.fi
* @notice The **UniswapV3Product** can be used to purchase coverage for **UniswapV3 LP** positions.
*/ | NatSpecMultiLine | setCoveredPlatform | function setCoveredPlatform(address uniV3Factory_) public override {
super.setCoveredPlatform(uniV3Factory_);
_uniV3Factory = IUniswapV3Factory(uniV3Factory_);
}
| /**
* @notice Changes the covered platform.
* Can only be called by the current [**governor**](/docs/protocol/governance).
* @dev Use this if the the protocol changes their registry but keeps the children contracts.
* A new version of the protocol will likely require a new Product.
* @param uniV3Factory_ The new Address Provider.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | {
"func_code_index": [
3567,
3752
]
} | 9,618 |
||
DesperateApeWives | contracts/DesperateApeWives.sol | 0xf1268733c6fb05ef6be9cf23d24436dcd6e0b35e | Solidity | DesperateApeWives | contract DesperateApeWives is Ownable, ERC721Enumerable, PaymentSplitter {
uint public constant MAX_WIVES = 10000;
uint private DAW_PRICE = 0.08 ether;
uint private walletLimit = 3;
string public PROVENANCE_HASH;
string private _baseURIExtended;
string private _contractURI;
bool public _isSaleLive = false;
bool private locked;
bool private PROVENANCE_LOCK = false;
uint public _reserved;
//Desperate Ape Wives Release Time -
uint public presaleStart = 1635260400; // October 26th 11AM EST
uint public presaleEnd = 1635303600; // October 26th 11PM EST
uint public publicSale = 1635350400; // October 27th 12PM EST
struct Account {
uint nftsReserved;
uint walletLimit;
uint mintedNFTs;
bool isEarlySupporter;
bool isWhitelist;
bool isAdmin;
}
mapping(address => Account) public accounts;
event Mint(address indexed sender, uint totalSupply);
event PermanentURI(string _value, uint256 indexed _id);
address[] private _team;
uint[] private _team_shares;
address private donation;
constructor(address[] memory team, uint[] memory team_shares, address[] memory admins, address d1)
ERC721("Desperate ApeWives", "DAW")
PaymentSplitter(team, team_shares)
{
_baseURIExtended = "ipfs://QmbmjFdnvbYzvD6QfQzLg75TT6Du3hw4rx5Kh1uuqMqevV/";
accounts[msg.sender] = Account( 0, 0, 0, true, true, true);
accounts[admins[0]] = Account( 12, 0, 0, false, false, true);
accounts[admins[1]] = Account( 13, 0, 0, false, false, true);
accounts[admins[2]] = Account( 12, 0, 0, false, false, true);
accounts[admins[3]] = Account( 13, 0, 0, false, false, true);
accounts[admins[4]] = Account( 16, 0, 0, false, false, true);
accounts[admins[5]] = Account( 17, 0, 0, false, false, true);
accounts[admins[6]] = Account( 17, 0, 0, false, false, true);
accounts[admins[7]] = Account( 90, 0, 0, false, false, true);
_reserved = 190;
_team = team;
_team_shares = team_shares;
donation = d1;
}
// Modifiers
modifier onlyAdmin() {
require(accounts[msg.sender].isAdmin == true, "Nice try! You need to be an admin");
_;
}
modifier noReentrant() {
require(!locked, "No re-entrancy");
locked = true;
_;
locked = false;
}
// End Modifier
// Setters
function setAdmin(address _addr) external onlyOwner {
accounts[_addr].isAdmin = !accounts[_addr].isAdmin;
}
function setProvenanceHash(string memory _provenanceHash) external onlyOwner {
require(PROVENANCE_LOCK == false);
PROVENANCE_HASH = _provenanceHash;
}
function lockProvenance() external onlyOwner {
PROVENANCE_LOCK = true;
}
function setBaseURI(string memory _newURI) external onlyAdmin {
_baseURIExtended = _newURI;
}
function setContractURI(string memory _newURI) external onlyAdmin {
_contractURI = _newURI;
}
function deactivateSale() external onlyOwner {
_isSaleLive = false;
}
function activateSale() external onlyOwner {
_isSaleLive = true;
}
function setEarlySupporters(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 10;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setEarlySupporters5(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 5;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setWhitelist(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 2;
accounts[_addr[i]].isWhitelist = true;
}
}
function setSaleTimes(uint[] memory _newTimes) external onlyAdmin {
require(_newTimes.length == 3, "You need to update all times at once");
presaleStart = _newTimes[0];
presaleEnd = _newTimes[1];
publicSale = _newTimes[2];
}
// End Setter
// Getters
function getSaleTimes() public view returns (uint, uint, uint) {
return (presaleStart, presaleEnd, publicSale);
}
// For OpenSea
function contractURI() public view returns (string memory) {
return _contractURI;
}
// For Metadata
function _baseURI() internal view virtual override returns (string memory) {
return _baseURIExtended;
}
// End Getter
// Business Logic
function claimDonations() external onlyAdmin {
require(totalSupply() + 2 <= (MAX_WIVES - _reserved), "You would exceed the limit");
_safeMint(donation, 1); // Good Dollar Donation
_safeMint(donation, 2); // Brest Cancer Donation
emit Mint(msg.sender, totalSupply());
}
function adminMint() external onlyAdmin {
uint _amount = accounts[msg.sender].nftsReserved;
require(accounts[msg.sender].isAdmin == true,"Nice Try! Only an admin can mint");
require(_amount > 0, 'Need to have reserved supply');
require(totalSupply() + _amount <= MAX_WIVES, "You would exceed the limit");
accounts[msg.sender].nftsReserved -= _amount;
_reserved = _reserved - _amount;
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function airDropMany(address[] memory _addr) external onlyAdmin {
require(totalSupply() + _addr.length <= (MAX_WIVES - _reserved), "You would exceed the limit");
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _addr.length; i++) {
id++;
_safeMint(_addr[i], id);
emit Mint(msg.sender, totalSupply());
}
}
function mintWife(uint _amount) external payable noReentrant {
// CHECK BASIC SALE CONDITIONS
require(_isSaleLive, "Sale must be active to mint");
require(block.timestamp >= presaleStart, "You must wait till presale begins to mint");
require(_amount > 0, "Must mint at least one token and under 10");
require(totalSupply() + _amount <= (MAX_WIVES - _reserved), "Purchase would exceed max supply of Apes");
require(msg.value >= (DAW_PRICE * _amount), "Ether value sent is not correct");
require(!isContract(msg.sender), "Contracts can't mint");
if(block.timestamp >= publicSale) {
require((_amount + accounts[msg.sender].mintedNFTs) <= walletLimit, "Sorry you can only mint 3 per wallet");
} else if(block.timestamp >= presaleEnd) {
require(false, "Presale has Ended please Wait till Public sale");
} else if(block.timestamp >= presaleStart) {
require(accounts[msg.sender].isWhitelist || accounts[msg.sender].isEarlySupporter, "Sorry you need to be on Whitelist");
require((_amount + accounts[msg.sender].mintedNFTs) <= accounts[msg.sender].walletLimit, "Wallet Limit Reached");
}
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
accounts[msg.sender].mintedNFTs++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function releaseFunds() external onlyAdmin {
for (uint i = 0; i < _team.length; i++) {
release(payable(_team[i]));
}
}
// helper
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
} | setAdmin | function setAdmin(address _addr) external onlyOwner {
accounts[_addr].isAdmin = !accounts[_addr].isAdmin;
}
| // End Modifier
// Setters | LineComment | v0.8.2+commit.661d1103 | MIT | {
"func_code_index": [
2483,
2606
]
} | 9,619 |
|||
DesperateApeWives | contracts/DesperateApeWives.sol | 0xf1268733c6fb05ef6be9cf23d24436dcd6e0b35e | Solidity | DesperateApeWives | contract DesperateApeWives is Ownable, ERC721Enumerable, PaymentSplitter {
uint public constant MAX_WIVES = 10000;
uint private DAW_PRICE = 0.08 ether;
uint private walletLimit = 3;
string public PROVENANCE_HASH;
string private _baseURIExtended;
string private _contractURI;
bool public _isSaleLive = false;
bool private locked;
bool private PROVENANCE_LOCK = false;
uint public _reserved;
//Desperate Ape Wives Release Time -
uint public presaleStart = 1635260400; // October 26th 11AM EST
uint public presaleEnd = 1635303600; // October 26th 11PM EST
uint public publicSale = 1635350400; // October 27th 12PM EST
struct Account {
uint nftsReserved;
uint walletLimit;
uint mintedNFTs;
bool isEarlySupporter;
bool isWhitelist;
bool isAdmin;
}
mapping(address => Account) public accounts;
event Mint(address indexed sender, uint totalSupply);
event PermanentURI(string _value, uint256 indexed _id);
address[] private _team;
uint[] private _team_shares;
address private donation;
constructor(address[] memory team, uint[] memory team_shares, address[] memory admins, address d1)
ERC721("Desperate ApeWives", "DAW")
PaymentSplitter(team, team_shares)
{
_baseURIExtended = "ipfs://QmbmjFdnvbYzvD6QfQzLg75TT6Du3hw4rx5Kh1uuqMqevV/";
accounts[msg.sender] = Account( 0, 0, 0, true, true, true);
accounts[admins[0]] = Account( 12, 0, 0, false, false, true);
accounts[admins[1]] = Account( 13, 0, 0, false, false, true);
accounts[admins[2]] = Account( 12, 0, 0, false, false, true);
accounts[admins[3]] = Account( 13, 0, 0, false, false, true);
accounts[admins[4]] = Account( 16, 0, 0, false, false, true);
accounts[admins[5]] = Account( 17, 0, 0, false, false, true);
accounts[admins[6]] = Account( 17, 0, 0, false, false, true);
accounts[admins[7]] = Account( 90, 0, 0, false, false, true);
_reserved = 190;
_team = team;
_team_shares = team_shares;
donation = d1;
}
// Modifiers
modifier onlyAdmin() {
require(accounts[msg.sender].isAdmin == true, "Nice try! You need to be an admin");
_;
}
modifier noReentrant() {
require(!locked, "No re-entrancy");
locked = true;
_;
locked = false;
}
// End Modifier
// Setters
function setAdmin(address _addr) external onlyOwner {
accounts[_addr].isAdmin = !accounts[_addr].isAdmin;
}
function setProvenanceHash(string memory _provenanceHash) external onlyOwner {
require(PROVENANCE_LOCK == false);
PROVENANCE_HASH = _provenanceHash;
}
function lockProvenance() external onlyOwner {
PROVENANCE_LOCK = true;
}
function setBaseURI(string memory _newURI) external onlyAdmin {
_baseURIExtended = _newURI;
}
function setContractURI(string memory _newURI) external onlyAdmin {
_contractURI = _newURI;
}
function deactivateSale() external onlyOwner {
_isSaleLive = false;
}
function activateSale() external onlyOwner {
_isSaleLive = true;
}
function setEarlySupporters(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 10;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setEarlySupporters5(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 5;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setWhitelist(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 2;
accounts[_addr[i]].isWhitelist = true;
}
}
function setSaleTimes(uint[] memory _newTimes) external onlyAdmin {
require(_newTimes.length == 3, "You need to update all times at once");
presaleStart = _newTimes[0];
presaleEnd = _newTimes[1];
publicSale = _newTimes[2];
}
// End Setter
// Getters
function getSaleTimes() public view returns (uint, uint, uint) {
return (presaleStart, presaleEnd, publicSale);
}
// For OpenSea
function contractURI() public view returns (string memory) {
return _contractURI;
}
// For Metadata
function _baseURI() internal view virtual override returns (string memory) {
return _baseURIExtended;
}
// End Getter
// Business Logic
function claimDonations() external onlyAdmin {
require(totalSupply() + 2 <= (MAX_WIVES - _reserved), "You would exceed the limit");
_safeMint(donation, 1); // Good Dollar Donation
_safeMint(donation, 2); // Brest Cancer Donation
emit Mint(msg.sender, totalSupply());
}
function adminMint() external onlyAdmin {
uint _amount = accounts[msg.sender].nftsReserved;
require(accounts[msg.sender].isAdmin == true,"Nice Try! Only an admin can mint");
require(_amount > 0, 'Need to have reserved supply');
require(totalSupply() + _amount <= MAX_WIVES, "You would exceed the limit");
accounts[msg.sender].nftsReserved -= _amount;
_reserved = _reserved - _amount;
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function airDropMany(address[] memory _addr) external onlyAdmin {
require(totalSupply() + _addr.length <= (MAX_WIVES - _reserved), "You would exceed the limit");
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _addr.length; i++) {
id++;
_safeMint(_addr[i], id);
emit Mint(msg.sender, totalSupply());
}
}
function mintWife(uint _amount) external payable noReentrant {
// CHECK BASIC SALE CONDITIONS
require(_isSaleLive, "Sale must be active to mint");
require(block.timestamp >= presaleStart, "You must wait till presale begins to mint");
require(_amount > 0, "Must mint at least one token and under 10");
require(totalSupply() + _amount <= (MAX_WIVES - _reserved), "Purchase would exceed max supply of Apes");
require(msg.value >= (DAW_PRICE * _amount), "Ether value sent is not correct");
require(!isContract(msg.sender), "Contracts can't mint");
if(block.timestamp >= publicSale) {
require((_amount + accounts[msg.sender].mintedNFTs) <= walletLimit, "Sorry you can only mint 3 per wallet");
} else if(block.timestamp >= presaleEnd) {
require(false, "Presale has Ended please Wait till Public sale");
} else if(block.timestamp >= presaleStart) {
require(accounts[msg.sender].isWhitelist || accounts[msg.sender].isEarlySupporter, "Sorry you need to be on Whitelist");
require((_amount + accounts[msg.sender].mintedNFTs) <= accounts[msg.sender].walletLimit, "Wallet Limit Reached");
}
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
accounts[msg.sender].mintedNFTs++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function releaseFunds() external onlyAdmin {
for (uint i = 0; i < _team.length; i++) {
release(payable(_team[i]));
}
}
// helper
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
} | getSaleTimes | function getSaleTimes() public view returns (uint, uint, uint) {
return (presaleStart, presaleEnd, publicSale);
}
| // End Setter
// Getters | LineComment | v0.8.2+commit.661d1103 | MIT | {
"func_code_index": [
4300,
4429
]
} | 9,620 |
|||
DesperateApeWives | contracts/DesperateApeWives.sol | 0xf1268733c6fb05ef6be9cf23d24436dcd6e0b35e | Solidity | DesperateApeWives | contract DesperateApeWives is Ownable, ERC721Enumerable, PaymentSplitter {
uint public constant MAX_WIVES = 10000;
uint private DAW_PRICE = 0.08 ether;
uint private walletLimit = 3;
string public PROVENANCE_HASH;
string private _baseURIExtended;
string private _contractURI;
bool public _isSaleLive = false;
bool private locked;
bool private PROVENANCE_LOCK = false;
uint public _reserved;
//Desperate Ape Wives Release Time -
uint public presaleStart = 1635260400; // October 26th 11AM EST
uint public presaleEnd = 1635303600; // October 26th 11PM EST
uint public publicSale = 1635350400; // October 27th 12PM EST
struct Account {
uint nftsReserved;
uint walletLimit;
uint mintedNFTs;
bool isEarlySupporter;
bool isWhitelist;
bool isAdmin;
}
mapping(address => Account) public accounts;
event Mint(address indexed sender, uint totalSupply);
event PermanentURI(string _value, uint256 indexed _id);
address[] private _team;
uint[] private _team_shares;
address private donation;
constructor(address[] memory team, uint[] memory team_shares, address[] memory admins, address d1)
ERC721("Desperate ApeWives", "DAW")
PaymentSplitter(team, team_shares)
{
_baseURIExtended = "ipfs://QmbmjFdnvbYzvD6QfQzLg75TT6Du3hw4rx5Kh1uuqMqevV/";
accounts[msg.sender] = Account( 0, 0, 0, true, true, true);
accounts[admins[0]] = Account( 12, 0, 0, false, false, true);
accounts[admins[1]] = Account( 13, 0, 0, false, false, true);
accounts[admins[2]] = Account( 12, 0, 0, false, false, true);
accounts[admins[3]] = Account( 13, 0, 0, false, false, true);
accounts[admins[4]] = Account( 16, 0, 0, false, false, true);
accounts[admins[5]] = Account( 17, 0, 0, false, false, true);
accounts[admins[6]] = Account( 17, 0, 0, false, false, true);
accounts[admins[7]] = Account( 90, 0, 0, false, false, true);
_reserved = 190;
_team = team;
_team_shares = team_shares;
donation = d1;
}
// Modifiers
modifier onlyAdmin() {
require(accounts[msg.sender].isAdmin == true, "Nice try! You need to be an admin");
_;
}
modifier noReentrant() {
require(!locked, "No re-entrancy");
locked = true;
_;
locked = false;
}
// End Modifier
// Setters
function setAdmin(address _addr) external onlyOwner {
accounts[_addr].isAdmin = !accounts[_addr].isAdmin;
}
function setProvenanceHash(string memory _provenanceHash) external onlyOwner {
require(PROVENANCE_LOCK == false);
PROVENANCE_HASH = _provenanceHash;
}
function lockProvenance() external onlyOwner {
PROVENANCE_LOCK = true;
}
function setBaseURI(string memory _newURI) external onlyAdmin {
_baseURIExtended = _newURI;
}
function setContractURI(string memory _newURI) external onlyAdmin {
_contractURI = _newURI;
}
function deactivateSale() external onlyOwner {
_isSaleLive = false;
}
function activateSale() external onlyOwner {
_isSaleLive = true;
}
function setEarlySupporters(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 10;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setEarlySupporters5(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 5;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setWhitelist(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 2;
accounts[_addr[i]].isWhitelist = true;
}
}
function setSaleTimes(uint[] memory _newTimes) external onlyAdmin {
require(_newTimes.length == 3, "You need to update all times at once");
presaleStart = _newTimes[0];
presaleEnd = _newTimes[1];
publicSale = _newTimes[2];
}
// End Setter
// Getters
function getSaleTimes() public view returns (uint, uint, uint) {
return (presaleStart, presaleEnd, publicSale);
}
// For OpenSea
function contractURI() public view returns (string memory) {
return _contractURI;
}
// For Metadata
function _baseURI() internal view virtual override returns (string memory) {
return _baseURIExtended;
}
// End Getter
// Business Logic
function claimDonations() external onlyAdmin {
require(totalSupply() + 2 <= (MAX_WIVES - _reserved), "You would exceed the limit");
_safeMint(donation, 1); // Good Dollar Donation
_safeMint(donation, 2); // Brest Cancer Donation
emit Mint(msg.sender, totalSupply());
}
function adminMint() external onlyAdmin {
uint _amount = accounts[msg.sender].nftsReserved;
require(accounts[msg.sender].isAdmin == true,"Nice Try! Only an admin can mint");
require(_amount > 0, 'Need to have reserved supply');
require(totalSupply() + _amount <= MAX_WIVES, "You would exceed the limit");
accounts[msg.sender].nftsReserved -= _amount;
_reserved = _reserved - _amount;
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function airDropMany(address[] memory _addr) external onlyAdmin {
require(totalSupply() + _addr.length <= (MAX_WIVES - _reserved), "You would exceed the limit");
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _addr.length; i++) {
id++;
_safeMint(_addr[i], id);
emit Mint(msg.sender, totalSupply());
}
}
function mintWife(uint _amount) external payable noReentrant {
// CHECK BASIC SALE CONDITIONS
require(_isSaleLive, "Sale must be active to mint");
require(block.timestamp >= presaleStart, "You must wait till presale begins to mint");
require(_amount > 0, "Must mint at least one token and under 10");
require(totalSupply() + _amount <= (MAX_WIVES - _reserved), "Purchase would exceed max supply of Apes");
require(msg.value >= (DAW_PRICE * _amount), "Ether value sent is not correct");
require(!isContract(msg.sender), "Contracts can't mint");
if(block.timestamp >= publicSale) {
require((_amount + accounts[msg.sender].mintedNFTs) <= walletLimit, "Sorry you can only mint 3 per wallet");
} else if(block.timestamp >= presaleEnd) {
require(false, "Presale has Ended please Wait till Public sale");
} else if(block.timestamp >= presaleStart) {
require(accounts[msg.sender].isWhitelist || accounts[msg.sender].isEarlySupporter, "Sorry you need to be on Whitelist");
require((_amount + accounts[msg.sender].mintedNFTs) <= accounts[msg.sender].walletLimit, "Wallet Limit Reached");
}
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
accounts[msg.sender].mintedNFTs++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function releaseFunds() external onlyAdmin {
for (uint i = 0; i < _team.length; i++) {
release(payable(_team[i]));
}
}
// helper
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
} | contractURI | function contractURI() public view returns (string memory) {
return _contractURI;
}
| // For OpenSea | LineComment | v0.8.2+commit.661d1103 | MIT | {
"func_code_index": [
4450,
4549
]
} | 9,621 |
|||
DesperateApeWives | contracts/DesperateApeWives.sol | 0xf1268733c6fb05ef6be9cf23d24436dcd6e0b35e | Solidity | DesperateApeWives | contract DesperateApeWives is Ownable, ERC721Enumerable, PaymentSplitter {
uint public constant MAX_WIVES = 10000;
uint private DAW_PRICE = 0.08 ether;
uint private walletLimit = 3;
string public PROVENANCE_HASH;
string private _baseURIExtended;
string private _contractURI;
bool public _isSaleLive = false;
bool private locked;
bool private PROVENANCE_LOCK = false;
uint public _reserved;
//Desperate Ape Wives Release Time -
uint public presaleStart = 1635260400; // October 26th 11AM EST
uint public presaleEnd = 1635303600; // October 26th 11PM EST
uint public publicSale = 1635350400; // October 27th 12PM EST
struct Account {
uint nftsReserved;
uint walletLimit;
uint mintedNFTs;
bool isEarlySupporter;
bool isWhitelist;
bool isAdmin;
}
mapping(address => Account) public accounts;
event Mint(address indexed sender, uint totalSupply);
event PermanentURI(string _value, uint256 indexed _id);
address[] private _team;
uint[] private _team_shares;
address private donation;
constructor(address[] memory team, uint[] memory team_shares, address[] memory admins, address d1)
ERC721("Desperate ApeWives", "DAW")
PaymentSplitter(team, team_shares)
{
_baseURIExtended = "ipfs://QmbmjFdnvbYzvD6QfQzLg75TT6Du3hw4rx5Kh1uuqMqevV/";
accounts[msg.sender] = Account( 0, 0, 0, true, true, true);
accounts[admins[0]] = Account( 12, 0, 0, false, false, true);
accounts[admins[1]] = Account( 13, 0, 0, false, false, true);
accounts[admins[2]] = Account( 12, 0, 0, false, false, true);
accounts[admins[3]] = Account( 13, 0, 0, false, false, true);
accounts[admins[4]] = Account( 16, 0, 0, false, false, true);
accounts[admins[5]] = Account( 17, 0, 0, false, false, true);
accounts[admins[6]] = Account( 17, 0, 0, false, false, true);
accounts[admins[7]] = Account( 90, 0, 0, false, false, true);
_reserved = 190;
_team = team;
_team_shares = team_shares;
donation = d1;
}
// Modifiers
modifier onlyAdmin() {
require(accounts[msg.sender].isAdmin == true, "Nice try! You need to be an admin");
_;
}
modifier noReentrant() {
require(!locked, "No re-entrancy");
locked = true;
_;
locked = false;
}
// End Modifier
// Setters
function setAdmin(address _addr) external onlyOwner {
accounts[_addr].isAdmin = !accounts[_addr].isAdmin;
}
function setProvenanceHash(string memory _provenanceHash) external onlyOwner {
require(PROVENANCE_LOCK == false);
PROVENANCE_HASH = _provenanceHash;
}
function lockProvenance() external onlyOwner {
PROVENANCE_LOCK = true;
}
function setBaseURI(string memory _newURI) external onlyAdmin {
_baseURIExtended = _newURI;
}
function setContractURI(string memory _newURI) external onlyAdmin {
_contractURI = _newURI;
}
function deactivateSale() external onlyOwner {
_isSaleLive = false;
}
function activateSale() external onlyOwner {
_isSaleLive = true;
}
function setEarlySupporters(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 10;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setEarlySupporters5(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 5;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setWhitelist(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 2;
accounts[_addr[i]].isWhitelist = true;
}
}
function setSaleTimes(uint[] memory _newTimes) external onlyAdmin {
require(_newTimes.length == 3, "You need to update all times at once");
presaleStart = _newTimes[0];
presaleEnd = _newTimes[1];
publicSale = _newTimes[2];
}
// End Setter
// Getters
function getSaleTimes() public view returns (uint, uint, uint) {
return (presaleStart, presaleEnd, publicSale);
}
// For OpenSea
function contractURI() public view returns (string memory) {
return _contractURI;
}
// For Metadata
function _baseURI() internal view virtual override returns (string memory) {
return _baseURIExtended;
}
// End Getter
// Business Logic
function claimDonations() external onlyAdmin {
require(totalSupply() + 2 <= (MAX_WIVES - _reserved), "You would exceed the limit");
_safeMint(donation, 1); // Good Dollar Donation
_safeMint(donation, 2); // Brest Cancer Donation
emit Mint(msg.sender, totalSupply());
}
function adminMint() external onlyAdmin {
uint _amount = accounts[msg.sender].nftsReserved;
require(accounts[msg.sender].isAdmin == true,"Nice Try! Only an admin can mint");
require(_amount > 0, 'Need to have reserved supply');
require(totalSupply() + _amount <= MAX_WIVES, "You would exceed the limit");
accounts[msg.sender].nftsReserved -= _amount;
_reserved = _reserved - _amount;
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function airDropMany(address[] memory _addr) external onlyAdmin {
require(totalSupply() + _addr.length <= (MAX_WIVES - _reserved), "You would exceed the limit");
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _addr.length; i++) {
id++;
_safeMint(_addr[i], id);
emit Mint(msg.sender, totalSupply());
}
}
function mintWife(uint _amount) external payable noReentrant {
// CHECK BASIC SALE CONDITIONS
require(_isSaleLive, "Sale must be active to mint");
require(block.timestamp >= presaleStart, "You must wait till presale begins to mint");
require(_amount > 0, "Must mint at least one token and under 10");
require(totalSupply() + _amount <= (MAX_WIVES - _reserved), "Purchase would exceed max supply of Apes");
require(msg.value >= (DAW_PRICE * _amount), "Ether value sent is not correct");
require(!isContract(msg.sender), "Contracts can't mint");
if(block.timestamp >= publicSale) {
require((_amount + accounts[msg.sender].mintedNFTs) <= walletLimit, "Sorry you can only mint 3 per wallet");
} else if(block.timestamp >= presaleEnd) {
require(false, "Presale has Ended please Wait till Public sale");
} else if(block.timestamp >= presaleStart) {
require(accounts[msg.sender].isWhitelist || accounts[msg.sender].isEarlySupporter, "Sorry you need to be on Whitelist");
require((_amount + accounts[msg.sender].mintedNFTs) <= accounts[msg.sender].walletLimit, "Wallet Limit Reached");
}
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
accounts[msg.sender].mintedNFTs++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function releaseFunds() external onlyAdmin {
for (uint i = 0; i < _team.length; i++) {
release(payable(_team[i]));
}
}
// helper
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
} | _baseURI | function _baseURI() internal view virtual override returns (string memory) {
return _baseURIExtended;
}
| // For Metadata | LineComment | v0.8.2+commit.661d1103 | MIT | {
"func_code_index": [
4571,
4690
]
} | 9,622 |
|||
DesperateApeWives | contracts/DesperateApeWives.sol | 0xf1268733c6fb05ef6be9cf23d24436dcd6e0b35e | Solidity | DesperateApeWives | contract DesperateApeWives is Ownable, ERC721Enumerable, PaymentSplitter {
uint public constant MAX_WIVES = 10000;
uint private DAW_PRICE = 0.08 ether;
uint private walletLimit = 3;
string public PROVENANCE_HASH;
string private _baseURIExtended;
string private _contractURI;
bool public _isSaleLive = false;
bool private locked;
bool private PROVENANCE_LOCK = false;
uint public _reserved;
//Desperate Ape Wives Release Time -
uint public presaleStart = 1635260400; // October 26th 11AM EST
uint public presaleEnd = 1635303600; // October 26th 11PM EST
uint public publicSale = 1635350400; // October 27th 12PM EST
struct Account {
uint nftsReserved;
uint walletLimit;
uint mintedNFTs;
bool isEarlySupporter;
bool isWhitelist;
bool isAdmin;
}
mapping(address => Account) public accounts;
event Mint(address indexed sender, uint totalSupply);
event PermanentURI(string _value, uint256 indexed _id);
address[] private _team;
uint[] private _team_shares;
address private donation;
constructor(address[] memory team, uint[] memory team_shares, address[] memory admins, address d1)
ERC721("Desperate ApeWives", "DAW")
PaymentSplitter(team, team_shares)
{
_baseURIExtended = "ipfs://QmbmjFdnvbYzvD6QfQzLg75TT6Du3hw4rx5Kh1uuqMqevV/";
accounts[msg.sender] = Account( 0, 0, 0, true, true, true);
accounts[admins[0]] = Account( 12, 0, 0, false, false, true);
accounts[admins[1]] = Account( 13, 0, 0, false, false, true);
accounts[admins[2]] = Account( 12, 0, 0, false, false, true);
accounts[admins[3]] = Account( 13, 0, 0, false, false, true);
accounts[admins[4]] = Account( 16, 0, 0, false, false, true);
accounts[admins[5]] = Account( 17, 0, 0, false, false, true);
accounts[admins[6]] = Account( 17, 0, 0, false, false, true);
accounts[admins[7]] = Account( 90, 0, 0, false, false, true);
_reserved = 190;
_team = team;
_team_shares = team_shares;
donation = d1;
}
// Modifiers
modifier onlyAdmin() {
require(accounts[msg.sender].isAdmin == true, "Nice try! You need to be an admin");
_;
}
modifier noReentrant() {
require(!locked, "No re-entrancy");
locked = true;
_;
locked = false;
}
// End Modifier
// Setters
function setAdmin(address _addr) external onlyOwner {
accounts[_addr].isAdmin = !accounts[_addr].isAdmin;
}
function setProvenanceHash(string memory _provenanceHash) external onlyOwner {
require(PROVENANCE_LOCK == false);
PROVENANCE_HASH = _provenanceHash;
}
function lockProvenance() external onlyOwner {
PROVENANCE_LOCK = true;
}
function setBaseURI(string memory _newURI) external onlyAdmin {
_baseURIExtended = _newURI;
}
function setContractURI(string memory _newURI) external onlyAdmin {
_contractURI = _newURI;
}
function deactivateSale() external onlyOwner {
_isSaleLive = false;
}
function activateSale() external onlyOwner {
_isSaleLive = true;
}
function setEarlySupporters(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 10;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setEarlySupporters5(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 5;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setWhitelist(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 2;
accounts[_addr[i]].isWhitelist = true;
}
}
function setSaleTimes(uint[] memory _newTimes) external onlyAdmin {
require(_newTimes.length == 3, "You need to update all times at once");
presaleStart = _newTimes[0];
presaleEnd = _newTimes[1];
publicSale = _newTimes[2];
}
// End Setter
// Getters
function getSaleTimes() public view returns (uint, uint, uint) {
return (presaleStart, presaleEnd, publicSale);
}
// For OpenSea
function contractURI() public view returns (string memory) {
return _contractURI;
}
// For Metadata
function _baseURI() internal view virtual override returns (string memory) {
return _baseURIExtended;
}
// End Getter
// Business Logic
function claimDonations() external onlyAdmin {
require(totalSupply() + 2 <= (MAX_WIVES - _reserved), "You would exceed the limit");
_safeMint(donation, 1); // Good Dollar Donation
_safeMint(donation, 2); // Brest Cancer Donation
emit Mint(msg.sender, totalSupply());
}
function adminMint() external onlyAdmin {
uint _amount = accounts[msg.sender].nftsReserved;
require(accounts[msg.sender].isAdmin == true,"Nice Try! Only an admin can mint");
require(_amount > 0, 'Need to have reserved supply');
require(totalSupply() + _amount <= MAX_WIVES, "You would exceed the limit");
accounts[msg.sender].nftsReserved -= _amount;
_reserved = _reserved - _amount;
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function airDropMany(address[] memory _addr) external onlyAdmin {
require(totalSupply() + _addr.length <= (MAX_WIVES - _reserved), "You would exceed the limit");
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _addr.length; i++) {
id++;
_safeMint(_addr[i], id);
emit Mint(msg.sender, totalSupply());
}
}
function mintWife(uint _amount) external payable noReentrant {
// CHECK BASIC SALE CONDITIONS
require(_isSaleLive, "Sale must be active to mint");
require(block.timestamp >= presaleStart, "You must wait till presale begins to mint");
require(_amount > 0, "Must mint at least one token and under 10");
require(totalSupply() + _amount <= (MAX_WIVES - _reserved), "Purchase would exceed max supply of Apes");
require(msg.value >= (DAW_PRICE * _amount), "Ether value sent is not correct");
require(!isContract(msg.sender), "Contracts can't mint");
if(block.timestamp >= publicSale) {
require((_amount + accounts[msg.sender].mintedNFTs) <= walletLimit, "Sorry you can only mint 3 per wallet");
} else if(block.timestamp >= presaleEnd) {
require(false, "Presale has Ended please Wait till Public sale");
} else if(block.timestamp >= presaleStart) {
require(accounts[msg.sender].isWhitelist || accounts[msg.sender].isEarlySupporter, "Sorry you need to be on Whitelist");
require((_amount + accounts[msg.sender].mintedNFTs) <= accounts[msg.sender].walletLimit, "Wallet Limit Reached");
}
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
accounts[msg.sender].mintedNFTs++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function releaseFunds() external onlyAdmin {
for (uint i = 0; i < _team.length; i++) {
release(payable(_team[i]));
}
}
// helper
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
} | claimDonations | function claimDonations() external onlyAdmin {
require(totalSupply() + 2 <= (MAX_WIVES - _reserved), "You would exceed the limit");
_safeMint(donation, 1); // Good Dollar Donation
_safeMint(donation, 2); // Brest Cancer Donation
emit Mint(msg.sender, totalSupply());
}
| // End Getter
// Business Logic | LineComment | v0.8.2+commit.661d1103 | MIT | {
"func_code_index": [
4734,
5043
]
} | 9,623 |
|||
DesperateApeWives | contracts/DesperateApeWives.sol | 0xf1268733c6fb05ef6be9cf23d24436dcd6e0b35e | Solidity | DesperateApeWives | contract DesperateApeWives is Ownable, ERC721Enumerable, PaymentSplitter {
uint public constant MAX_WIVES = 10000;
uint private DAW_PRICE = 0.08 ether;
uint private walletLimit = 3;
string public PROVENANCE_HASH;
string private _baseURIExtended;
string private _contractURI;
bool public _isSaleLive = false;
bool private locked;
bool private PROVENANCE_LOCK = false;
uint public _reserved;
//Desperate Ape Wives Release Time -
uint public presaleStart = 1635260400; // October 26th 11AM EST
uint public presaleEnd = 1635303600; // October 26th 11PM EST
uint public publicSale = 1635350400; // October 27th 12PM EST
struct Account {
uint nftsReserved;
uint walletLimit;
uint mintedNFTs;
bool isEarlySupporter;
bool isWhitelist;
bool isAdmin;
}
mapping(address => Account) public accounts;
event Mint(address indexed sender, uint totalSupply);
event PermanentURI(string _value, uint256 indexed _id);
address[] private _team;
uint[] private _team_shares;
address private donation;
constructor(address[] memory team, uint[] memory team_shares, address[] memory admins, address d1)
ERC721("Desperate ApeWives", "DAW")
PaymentSplitter(team, team_shares)
{
_baseURIExtended = "ipfs://QmbmjFdnvbYzvD6QfQzLg75TT6Du3hw4rx5Kh1uuqMqevV/";
accounts[msg.sender] = Account( 0, 0, 0, true, true, true);
accounts[admins[0]] = Account( 12, 0, 0, false, false, true);
accounts[admins[1]] = Account( 13, 0, 0, false, false, true);
accounts[admins[2]] = Account( 12, 0, 0, false, false, true);
accounts[admins[3]] = Account( 13, 0, 0, false, false, true);
accounts[admins[4]] = Account( 16, 0, 0, false, false, true);
accounts[admins[5]] = Account( 17, 0, 0, false, false, true);
accounts[admins[6]] = Account( 17, 0, 0, false, false, true);
accounts[admins[7]] = Account( 90, 0, 0, false, false, true);
_reserved = 190;
_team = team;
_team_shares = team_shares;
donation = d1;
}
// Modifiers
modifier onlyAdmin() {
require(accounts[msg.sender].isAdmin == true, "Nice try! You need to be an admin");
_;
}
modifier noReentrant() {
require(!locked, "No re-entrancy");
locked = true;
_;
locked = false;
}
// End Modifier
// Setters
function setAdmin(address _addr) external onlyOwner {
accounts[_addr].isAdmin = !accounts[_addr].isAdmin;
}
function setProvenanceHash(string memory _provenanceHash) external onlyOwner {
require(PROVENANCE_LOCK == false);
PROVENANCE_HASH = _provenanceHash;
}
function lockProvenance() external onlyOwner {
PROVENANCE_LOCK = true;
}
function setBaseURI(string memory _newURI) external onlyAdmin {
_baseURIExtended = _newURI;
}
function setContractURI(string memory _newURI) external onlyAdmin {
_contractURI = _newURI;
}
function deactivateSale() external onlyOwner {
_isSaleLive = false;
}
function activateSale() external onlyOwner {
_isSaleLive = true;
}
function setEarlySupporters(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 10;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setEarlySupporters5(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 5;
accounts[_addr[i]].isEarlySupporter = true;
}
}
function setWhitelist(address[] memory _addr) external onlyAdmin {
for(uint i = 0; i < _addr.length; i++) {
accounts[_addr[i]].walletLimit = 2;
accounts[_addr[i]].isWhitelist = true;
}
}
function setSaleTimes(uint[] memory _newTimes) external onlyAdmin {
require(_newTimes.length == 3, "You need to update all times at once");
presaleStart = _newTimes[0];
presaleEnd = _newTimes[1];
publicSale = _newTimes[2];
}
// End Setter
// Getters
function getSaleTimes() public view returns (uint, uint, uint) {
return (presaleStart, presaleEnd, publicSale);
}
// For OpenSea
function contractURI() public view returns (string memory) {
return _contractURI;
}
// For Metadata
function _baseURI() internal view virtual override returns (string memory) {
return _baseURIExtended;
}
// End Getter
// Business Logic
function claimDonations() external onlyAdmin {
require(totalSupply() + 2 <= (MAX_WIVES - _reserved), "You would exceed the limit");
_safeMint(donation, 1); // Good Dollar Donation
_safeMint(donation, 2); // Brest Cancer Donation
emit Mint(msg.sender, totalSupply());
}
function adminMint() external onlyAdmin {
uint _amount = accounts[msg.sender].nftsReserved;
require(accounts[msg.sender].isAdmin == true,"Nice Try! Only an admin can mint");
require(_amount > 0, 'Need to have reserved supply');
require(totalSupply() + _amount <= MAX_WIVES, "You would exceed the limit");
accounts[msg.sender].nftsReserved -= _amount;
_reserved = _reserved - _amount;
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function airDropMany(address[] memory _addr) external onlyAdmin {
require(totalSupply() + _addr.length <= (MAX_WIVES - _reserved), "You would exceed the limit");
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _addr.length; i++) {
id++;
_safeMint(_addr[i], id);
emit Mint(msg.sender, totalSupply());
}
}
function mintWife(uint _amount) external payable noReentrant {
// CHECK BASIC SALE CONDITIONS
require(_isSaleLive, "Sale must be active to mint");
require(block.timestamp >= presaleStart, "You must wait till presale begins to mint");
require(_amount > 0, "Must mint at least one token and under 10");
require(totalSupply() + _amount <= (MAX_WIVES - _reserved), "Purchase would exceed max supply of Apes");
require(msg.value >= (DAW_PRICE * _amount), "Ether value sent is not correct");
require(!isContract(msg.sender), "Contracts can't mint");
if(block.timestamp >= publicSale) {
require((_amount + accounts[msg.sender].mintedNFTs) <= walletLimit, "Sorry you can only mint 3 per wallet");
} else if(block.timestamp >= presaleEnd) {
require(false, "Presale has Ended please Wait till Public sale");
} else if(block.timestamp >= presaleStart) {
require(accounts[msg.sender].isWhitelist || accounts[msg.sender].isEarlySupporter, "Sorry you need to be on Whitelist");
require((_amount + accounts[msg.sender].mintedNFTs) <= accounts[msg.sender].walletLimit, "Wallet Limit Reached");
}
// DO MINT
uint id = totalSupply();
for (uint i = 0; i < _amount; i++) {
id++;
accounts[msg.sender].mintedNFTs++;
_safeMint(msg.sender, id);
emit Mint(msg.sender, totalSupply());
}
}
function releaseFunds() external onlyAdmin {
for (uint i = 0; i < _team.length; i++) {
release(payable(_team[i]));
}
}
// helper
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
} | isContract | function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
| // helper | LineComment | v0.8.2+commit.661d1103 | MIT | {
"func_code_index": [
7750,
8133
]
} | 9,624 |
|||
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721TokenReceiver | interface ERC721TokenReceiver {
/**
* @notice The contract address is always the message sender. A wallet/broker/auction application
* MUST implement the wallet interface if it will accept safe transfers.
* @dev Handle the receipt of a NFT. The ERC721 smart contract calls this function on the
* recipient after a `transfer`. This function MAY throw to revert and reject the transfer. Return
* of other than the magic value MUST result in the transaction being reverted.
* Returns `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` unless throwing.
* @param _operator The address which called `safeTransferFrom` function.
* @param _from The address which previously owned the token.
* @param _tokenId The NFT identifier which is being transferred.
* @param _data Additional data with no specified format.
* @return Returns `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
*/
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes calldata _data
) external returns (bytes4);
} | /**
* @dev ERC-721 interface for accepting safe transfers.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | onERC721Received | function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes calldata _data
) external returns (bytes4);
| /**
* @notice The contract address is always the message sender. A wallet/broker/auction application
* MUST implement the wallet interface if it will accept safe transfers.
* @dev Handle the receipt of a NFT. The ERC721 smart contract calls this function on the
* recipient after a `transfer`. This function MAY throw to revert and reject the transfer. Return
* of other than the magic value MUST result in the transaction being reverted.
* Returns `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` unless throwing.
* @param _operator The address which called `safeTransferFrom` function.
* @param _from The address which previously owned the token.
* @param _tokenId The NFT identifier which is being transferred.
* @param _data Additional data with no specified format.
* @return Returns `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
996,
1170
]
} | 9,625 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | AddressUtils | library AddressUtils {
/**
* @dev Returns whether the target address is a contract.
* @param _addr Address to check.
* @return addressCheck True if _addr is a contract, false if not.
*/
function isContract(address _addr)
internal
view
returns (bool addressCheck)
{
// This method relies in extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly {
codehash := extcodehash(_addr)
} // solhint-disable-line
addressCheck = (codehash != 0x0 && codehash != accountHash);
}
} | /**
* @notice Based on:
* https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Address.sol
* Requires EIP-1052.
* @dev Utility library of inline functions on addresses.
*/ | NatSpecMultiLine | isContract | function isContract(address _addr)
internal
view
returns (bool addressCheck)
{
// This method relies in extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly {
codehash := extcodehash(_addr)
} // solhint-disable-line
addressCheck = (codehash != 0x0 && codehash != accountHash);
}
| /**
* @dev Returns whether the target address is a contract.
* @param _addr Address to check.
* @return addressCheck True if _addr is a contract, false if not.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
216,
1069
]
} | 9,626 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | Ownable | contract Ownable {
/**
* @dev Error constants.
*/
string public constant NOT_CURRENT_OWNER = "018001";
string public constant CANNOT_TRANSFER_TO_ZERO_ADDRESS = "018002";
/**
* @dev Current owner address.
*/
address public owner;
/**
* @dev An event which is triggered when the owner is changed.
* @param previousOwner The address of the previous owner.
* @param newOwner The address of the new owner.
*/
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The constructor sets the original `owner` of the contract to the sender account.
*/
constructor() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner, NOT_CURRENT_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), CANNOT_TRANSFER_TO_ZERO_ADDRESS);
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
} | /**
* @dev The contract has an owner address, and provides basic authorization control whitch
* simplifies the implementation of user permissions. This contract is based on the source code at:
* https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address _newOwner) public onlyOwner {
require(_newOwner != address(0), CANNOT_TRANSFER_TO_ZERO_ADDRESS);
emit 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.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
1137,
1371
]
} | 9,627 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721Metadata | interface ERC721Metadata {
/**
* @dev Returns a descriptive name for a collection of NFTs in this contract.
* @return _name Representing name.
*/
function name() external view returns (string memory _name);
/**
* @dev Returns a abbreviated name for a collection of NFTs in this contract.
* @return _symbol Representing symbol.
*/
function symbol() external view returns (string memory _symbol);
/**
* @dev Returns a distinct Uniform Resource Identifier (URI) for a given asset. It Throws if
* `_tokenId` is not a valid NFT. URIs are defined in RFC3986. The URI may point to a JSON file
* that conforms to the "ERC721 Metadata JSON Schema".
* @return URI of _tokenId.
*/
function tokenURI(uint256 _tokenId) external view returns (string memory);
} | /**
* @dev Optional metadata extension for ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | name | function name() external view returns (string memory _name);
| /**
* @dev Returns a descriptive name for a collection of NFTs in this contract.
* @return _name Representing name.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
170,
235
]
} | 9,628 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721Metadata | interface ERC721Metadata {
/**
* @dev Returns a descriptive name for a collection of NFTs in this contract.
* @return _name Representing name.
*/
function name() external view returns (string memory _name);
/**
* @dev Returns a abbreviated name for a collection of NFTs in this contract.
* @return _symbol Representing symbol.
*/
function symbol() external view returns (string memory _symbol);
/**
* @dev Returns a distinct Uniform Resource Identifier (URI) for a given asset. It Throws if
* `_tokenId` is not a valid NFT. URIs are defined in RFC3986. The URI may point to a JSON file
* that conforms to the "ERC721 Metadata JSON Schema".
* @return URI of _tokenId.
*/
function tokenURI(uint256 _tokenId) external view returns (string memory);
} | /**
* @dev Optional metadata extension for ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | symbol | function symbol() external view returns (string memory _symbol);
| /**
* @dev Returns a abbreviated name for a collection of NFTs in this contract.
* @return _symbol Representing symbol.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
384,
453
]
} | 9,629 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721Metadata | interface ERC721Metadata {
/**
* @dev Returns a descriptive name for a collection of NFTs in this contract.
* @return _name Representing name.
*/
function name() external view returns (string memory _name);
/**
* @dev Returns a abbreviated name for a collection of NFTs in this contract.
* @return _symbol Representing symbol.
*/
function symbol() external view returns (string memory _symbol);
/**
* @dev Returns a distinct Uniform Resource Identifier (URI) for a given asset. It Throws if
* `_tokenId` is not a valid NFT. URIs are defined in RFC3986. The URI may point to a JSON file
* that conforms to the "ERC721 Metadata JSON Schema".
* @return URI of _tokenId.
*/
function tokenURI(uint256 _tokenId) external view returns (string memory);
} | /**
* @dev Optional metadata extension for ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | tokenURI | function tokenURI(uint256 _tokenId) external view returns (string memory);
| /**
* @dev Returns a distinct Uniform Resource Identifier (URI) for a given asset. It Throws if
* `_tokenId` is not a valid NFT. URIs are defined in RFC3986. The URI may point to a JSON file
* that conforms to the "ERC721 Metadata JSON Schema".
* @return URI of _tokenId.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
766,
845
]
} | 9,630 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC165 | interface ERC165 {
/**
* @dev Checks if the smart contract includes a specific interface.
* This function uses less than 30,000 gas.
* @param _interfaceID The interface identifier, as specified in ERC-165.
* @return True if _interfaceID is supported, false otherwise.
*/
function supportsInterface(bytes4 _interfaceID)
external
view
returns (bool);
} | /**
* @dev A standard for detecting smart contract interfaces.
* See: https://eips.ethereum.org/EIPS/eip-165.
*/ | NatSpecMultiLine | supportsInterface | function supportsInterface(bytes4 _interfaceID)
external
view
returns (bool);
| /**
* @dev Checks if the smart contract includes a specific interface.
* This function uses less than 30,000 gas.
* @param _interfaceID The interface identifier, as specified in ERC-165.
* @return True if _interfaceID is supported, false otherwise.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
307,
416
]
} | 9,631 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | SupportsInterface | contract SupportsInterface is ERC165 {
/**
* @dev Mapping of supported intefraces. You must not set element 0xffffffff to true.
*/
mapping(bytes4 => bool) internal supportedInterfaces;
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x01ffc9a7] = true; // ERC165
}
/**
* @dev Function to check which interfaces are suported by this contract.
* @param _interfaceID Id of the interface.
* @return True if _interfaceID is supported, false otherwise.
*/
function supportsInterface(bytes4 _interfaceID)
external
view
override
returns (bool)
{
return supportedInterfaces[_interfaceID];
}
} | /**
* @dev Implementation of standard for detect smart contract interfaces.
*/ | NatSpecMultiLine | supportsInterface | function supportsInterface(bytes4 _interfaceID)
external
view
override
returns (bool)
{
return supportedInterfaces[_interfaceID];
}
| /**
* @dev Function to check which interfaces are suported by this contract.
* @param _interfaceID Id of the interface.
* @return True if _interfaceID is supported, false otherwise.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
566,
757
]
} | 9,632 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721 | interface ERC721 {
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/
function approve(address _approved, uint256 _tokenId) external;
/**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
} | /**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | safeTransferFrom | function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
| /**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
2145,
2296
]
} | 9,633 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721 | interface ERC721 {
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/
function approve(address _approved, uint256 _tokenId) external;
/**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
} | /**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | safeTransferFrom | function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
| /**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
2721,
2841
]
} | 9,634 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721 | interface ERC721 {
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/
function approve(address _approved, uint256 _tokenId) external;
/**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
} | /**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
| /**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
3435,
3551
]
} | 9,635 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721 | interface ERC721 {
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/
function approve(address _approved, uint256 _tokenId) external;
/**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
} | /**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | approve | function approve(address _approved, uint256 _tokenId) external;
| /**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
3959,
4027
]
} | 9,636 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721 | interface ERC721 {
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/
function approve(address _approved, uint256 _tokenId) external;
/**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
} | /**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | setApprovalForAll | function setApprovalForAll(address _operator, bool _approved) external;
| /**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
4441,
4517
]
} | 9,637 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721 | interface ERC721 {
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/
function approve(address _approved, uint256 _tokenId) external;
/**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
} | /**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) external view returns (uint256);
| /**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
4873,
4945
]
} | 9,638 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721 | interface ERC721 {
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/
function approve(address _approved, uint256 _tokenId) external;
/**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
} | /**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | ownerOf | function ownerOf(uint256 _tokenId) external view returns (address);
| /**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
5259,
5331
]
} | 9,639 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721 | interface ERC721 {
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/
function approve(address _approved, uint256 _tokenId) external;
/**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
} | /**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | getApproved | function getApproved(uint256 _tokenId) external view returns (address);
| /**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
5586,
5662
]
} | 9,640 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | ERC721 | interface ERC721 {
/**
* @dev Emits when ownership of any NFT changes by any mechanism. This event emits when NFTs are
* created (`from` == 0) and destroyed (`to` == 0). Exception: during contract creation, any
* number of NFTs may be created and assigned without emitting Transfer. At the time of any
* transfer, the approved address for that NFT (if any) is reset to none.
*/
event Transfer(
address indexed _from,
address indexed _to,
uint256 indexed _tokenId
);
/**
* @dev This emits when the approved address for an NFT is changed or reaffirmed. The zero
* address indicates there is no approved address. When a Transfer event emits, this also
* indicates that the approved address for that NFT (if any) is reset to none.
*/
event Approval(
address indexed _owner,
address indexed _approved,
uint256 indexed _tokenId
);
/**
* @dev This emits when an operator is enabled or disabled for an owner. The operator can manage
* all NFTs of the owner.
*/
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
bool _approved
);
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external;
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to ""
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external;
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @param _approved The new approved NFT controller.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _tokenId The NFT to approve.
*/
function approve(address _approved, uint256 _tokenId) external;
/**
* @notice The contract MUST allow multiple operators per owner.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @notice Count all NFTs assigned to an owner.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner) external view returns (uint256);
/**
* @notice Find the owner of an NFT.
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId) external view returns (address);
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId The NFT to find the approved address for.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId) external view returns (address);
/**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
} | /**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/ | NatSpecMultiLine | isApprovedForAll | function isApprovedForAll(address _owner, address _operator)
external
view
returns (bool);
| /**
* @notice Query if an address is an authorized operator for another address.
* @dev Returns true if `_operator` is an approved operator for `_owner`, false otherwise.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
6046,
6168
]
} | 9,641 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | safeTransferFrom | function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
| /**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
3721,
3946
]
} | 9,642 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | safeTransferFrom | function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
| /**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
4372,
4563
]
} | 9,643 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
| /**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
5156,
5523
]
} | 9,644 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | approve | function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
| /**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
5955,
6333
]
} | 9,645 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | setApprovalForAll | function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
| /**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
6755,
6997
]
} | 9,646 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
| /**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
7300,
7527
]
} | 9,647 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | ownerOf | function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
| /**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
7806,
8037
]
} | 9,648 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | getApproved | function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
| /**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
8290,
8496
]
} | 9,649 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | isApprovedForAll | function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
| /**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
8774,
8980
]
} | 9,650 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _transfer | function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
| /**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
9180,
9459
]
} | 9,651 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _mint | function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
| /**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
9863,
10155
]
} | 9,652 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _burn | function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
| /**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
10571,
10848
]
} | 9,653 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _removeNFToken | function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
| /**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
11132,
11357
]
} | 9,654 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _addNFToken | function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
| /**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
11633,
11866
]
} | 9,655 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _getOwnerNFTCount | function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
| /**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
12170,
12352
]
} | 9,656 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _safeTransferFrom | function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
| /**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
12641,
13401
]
} | 9,657 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFToken | contract NFToken is ERC721, SupportsInterface {
using AddressUtils for address;
/**
* @dev List of revert message codes. Implementing dApp should handle showing the correct message.
* Based on 0xcert framework error codes.
*/
string constant ZERO_ADDRESS = "003001";
string constant NOT_VALID_NFT = "003002";
string constant NOT_OWNER_OR_OPERATOR = "003003";
string constant NOT_OWNER_APPROVED_OR_OPERATOR = "003004";
string constant NOT_ABLE_TO_RECEIVE_NFT = "003005";
string constant NFT_ALREADY_EXISTS = "003006";
string constant NOT_OWNER = "003007";
string constant IS_OWNER = "003008";
/**
* @dev Magic value of a smart contract that can receive NFT.
* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
*/
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;
/**
* @dev A mapping from NFT ID to the address that owns it.
*/
mapping(uint256 => address) internal idToOwner;
/**
* @dev Mapping from NFT ID to approved address.
*/
mapping(uint256 => address) internal idToApproval;
/**
* @dev Mapping from owner address to count of their tokens.
*/
mapping(address => uint256) private ownerToNFTokenCount;
/**
* @dev Mapping from owner address to mapping of operator addresses.
*/
mapping(address => mapping(address => bool)) internal ownerToOperators;
/**
* @dev Guarantees that the msg.sender is an owner or operator of the given NFT.
* @param _tokenId ID of the NFT to validate.
*/
modifier canOperate(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that the msg.sender is allowed to transfer NFT.
* @param _tokenId ID of the NFT to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(
tokenOwner == msg.sender ||
idToApproval[_tokenId] == msg.sender ||
ownerToOperators[tokenOwner][msg.sender],
NOT_OWNER_APPROVED_OR_OPERATOR
);
_;
}
/**
* @dev Guarantees that _tokenId is a valid Token.
* @param _tokenId ID of the NFT to validate.
*/
modifier validNFToken(uint256 _tokenId) {
require(idToOwner[_tokenId] != address(0), NOT_VALID_NFT);
_;
}
/**
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x80ac58cd] = true; // ERC721
}
/**
* @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the
* approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is
* the zero address. Throws if `_tokenId` is not a valid NFT. When transfer is complete, this
* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata _data
) external override {
_safeTransferFrom(_from, _to, _tokenId, _data);
}
/**
* @notice This works identically to the other function with an extra data parameter, except this
* function just sets data to "".
* @dev Transfers the ownership of an NFT from one address to another address. This function can
* be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external override {
_safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @notice The caller is responsible to confirm that `_to` is capable of receiving NFTs or else
* they may be permanently lost.
* @dev Throws unless `msg.sender` is the current owner, an authorized operator, or the approved
* address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is the zero
* address. Throws if `_tokenId` is not a valid NFT. This function can be changed to payable.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
*/
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external override canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
}
/**
* @notice The zero address indicates there is no approved address. Throws unless `msg.sender` is
* the current NFT owner, or an authorized operator of the current owner.
* @dev Set or reaffirm the approved address for an NFT. This function can be changed to payable.
* @param _approved Address to be approved for the given NFT ID.
* @param _tokenId ID of the token to be approved.
*/
function approve(address _approved, uint256 _tokenId)
external
override
canOperate(_tokenId)
validNFToken(_tokenId)
{
address tokenOwner = idToOwner[_tokenId];
require(_approved != tokenOwner, IS_OWNER);
idToApproval[_tokenId] = _approved;
emit Approval(tokenOwner, _approved, _tokenId);
}
/**
* @notice This works even if sender doesn't own any tokens at the time.
* @dev Enables or disables approval for a third party ("operator") to manage all of
* `msg.sender`'s assets. It also emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operators is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
override
{
ownerToOperators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the number of NFTs owned by `_owner`. NFTs assigned to the zero address are
* considered invalid, and this function throws for queries about the zero address.
* @param _owner Address for whom to query the balance.
* @return Balance of _owner.
*/
function balanceOf(address _owner)
external
view
override
returns (uint256)
{
require(_owner != address(0), ZERO_ADDRESS);
return _getOwnerNFTCount(_owner);
}
/**
* @dev Returns the address of the owner of the NFT. NFTs assigned to the zero address are
* considered invalid, and queries about them do throw.
* @param _tokenId The identifier for an NFT.
* @return _owner Address of _tokenId owner.
*/
function ownerOf(uint256 _tokenId)
external
view
override
returns (address _owner)
{
_owner = idToOwner[_tokenId];
require(_owner != address(0), NOT_VALID_NFT);
}
/**
* @notice Throws if `_tokenId` is not a valid NFT.
* @dev Get the approved address for a single NFT.
* @param _tokenId ID of the NFT to query the approval of.
* @return Address that _tokenId is approved for.
*/
function getApproved(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (address)
{
return idToApproval[_tokenId];
}
/**
* @dev Checks if `_operator` is an approved operator for `_owner`.
* @param _owner The address that owns the NFTs.
* @param _operator The address that acts on behalf of the owner.
* @return True if approved for all, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
override
returns (bool)
{
return ownerToOperators[_owner][_operator];
}
/**
* @notice Does NO checks.
* @dev Actually performs the transfer.
* @param _to Address of a new owner.
* @param _tokenId The NFT that is being transferred.
*/
function _transfer(address _to, uint256 _tokenId) internal {
address from = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(from, _tokenId);
_addNFToken(_to, _tokenId);
emit Transfer(from, _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external
* mint function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function _mint(address _to, uint256 _tokenId) internal virtual {
require(_to != address(0), ZERO_ADDRESS);
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
_addNFToken(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @notice This is an internal function which should be called from user-implemented external burn
* function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
_clearApproval(_tokenId);
_removeNFToken(tokenOwner, _tokenId);
emit Transfer(tokenOwner, address(0), _tokenId);
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Removes a NFT from owner.
* @param _from Address from which we want to remove the NFT.
* @param _tokenId Which NFT we want to remove.
*/
function _removeNFToken(address _from, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == _from, NOT_OWNER);
ownerToNFTokenCount[_from] -= 1;
delete idToOwner[_tokenId];
}
/**
* @notice Use and override this function with caution. Wrong usage can have serious consequences.
* @dev Assigns a new NFT to owner.
* @param _to Address to which we want to add the NFT.
* @param _tokenId Which NFT we want to add.
*/
function _addNFToken(address _to, uint256 _tokenId) internal virtual {
require(idToOwner[_tokenId] == address(0), NFT_ALREADY_EXISTS);
idToOwner[_tokenId] = _to;
ownerToNFTokenCount[_to] += 1;
}
/**
* @dev Helper function that gets NFT count of owner. This is needed for overriding in enumerable
* extension to remove double storage (gas optimization) of owner NFT count.
* @param _owner Address for whom to query the count.
* @return Number of _owner NFTs.
*/
function _getOwnerNFTCount(address _owner)
internal
view
virtual
returns (uint256)
{
return ownerToNFTokenCount[_owner];
}
/**
* @dev Actually perform the safeTransferFrom.
* @param _from The current owner of the NFT.
* @param _to The new owner.
* @param _tokenId The NFT to transfer.
* @param _data Additional data with no specified format, sent in call to `_to`.
*/
function _safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
) private canTransfer(_tokenId) validNFToken(_tokenId) {
address tokenOwner = idToOwner[_tokenId];
require(tokenOwner == _from, NOT_OWNER);
require(_to != address(0), ZERO_ADDRESS);
_transfer(_to, _tokenId);
if (_to.isContract()) {
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
retval == MAGIC_ON_ERC721_RECEIVED,
NOT_ABLE_TO_RECEIVE_NFT
);
}
}
/**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/
function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
} | /**
* @dev Implementation of ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _clearApproval | function _clearApproval(uint256 _tokenId) private {
delete idToApproval[_tokenId];
}
| /**
* @dev Clears the current approval of a given NFT ID.
* @param _tokenId ID of the NFT to be transferred.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
13539,
13642
]
} | 9,658 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFTokenMetadata | contract NFTokenMetadata is NFToken, ERC721Metadata {
/**
* @dev A descriptive name for a collection of NFTs.
*/
string internal nftName;
/**
* @dev An abbreviated name for NFTokens.
*/
string internal nftSymbol;
/**
* @dev Mapping from NFT ID to metadata uri.
*/
mapping(uint256 => string) internal idToUri;
/**
* @notice When implementing this contract don't forget to set nftName and nftSymbol.
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x5b5e139f] = true; // ERC721Metadata
}
/**
* @dev Returns a descriptive name for a collection of NFTokens.
* @return _name Representing name.
*/
function name() external view override returns (string memory _name) {
_name = nftName;
}
/**
* @dev Returns an abbreviated name for NFTokens.
* @return _symbol Representing symbol.
*/
function symbol() external view override returns (string memory _symbol) {
_symbol = nftSymbol;
}
/**
* @dev A distinct URI (RFC 3986) for a given NFT.
* @param _tokenId Id for which we want uri.
* @return URI of _tokenId.
*/
function tokenURI(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (string memory)
{
return idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* burn function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual override {
super._burn(_tokenId);
delete idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Set a distinct URI (RFC 3986) for a given NFT ID.
* @param _tokenId Id for which we want URI.
* @param _uri String representing RFC 3986 URI.
*/
function _setTokenUri(uint256 _tokenId, string memory _uri)
internal
validNFToken(_tokenId)
{
idToUri[_tokenId] = _uri;
}
} | /**
* @dev Optional metadata implementation for ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | name | function name() external view override returns (string memory _name) {
_name = nftName;
}
| /**
* @dev Returns a descriptive name for a collection of NFTokens.
* @return _name Representing name.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
752,
860
]
} | 9,659 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFTokenMetadata | contract NFTokenMetadata is NFToken, ERC721Metadata {
/**
* @dev A descriptive name for a collection of NFTs.
*/
string internal nftName;
/**
* @dev An abbreviated name for NFTokens.
*/
string internal nftSymbol;
/**
* @dev Mapping from NFT ID to metadata uri.
*/
mapping(uint256 => string) internal idToUri;
/**
* @notice When implementing this contract don't forget to set nftName and nftSymbol.
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x5b5e139f] = true; // ERC721Metadata
}
/**
* @dev Returns a descriptive name for a collection of NFTokens.
* @return _name Representing name.
*/
function name() external view override returns (string memory _name) {
_name = nftName;
}
/**
* @dev Returns an abbreviated name for NFTokens.
* @return _symbol Representing symbol.
*/
function symbol() external view override returns (string memory _symbol) {
_symbol = nftSymbol;
}
/**
* @dev A distinct URI (RFC 3986) for a given NFT.
* @param _tokenId Id for which we want uri.
* @return URI of _tokenId.
*/
function tokenURI(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (string memory)
{
return idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* burn function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual override {
super._burn(_tokenId);
delete idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Set a distinct URI (RFC 3986) for a given NFT ID.
* @param _tokenId Id for which we want URI.
* @param _uri String representing RFC 3986 URI.
*/
function _setTokenUri(uint256 _tokenId, string memory _uri)
internal
validNFToken(_tokenId)
{
idToUri[_tokenId] = _uri;
}
} | /**
* @dev Optional metadata implementation for ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | symbol | function symbol() external view override returns (string memory _symbol) {
_symbol = nftSymbol;
}
| /**
* @dev Returns an abbreviated name for NFTokens.
* @return _symbol Representing symbol.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
981,
1097
]
} | 9,660 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFTokenMetadata | contract NFTokenMetadata is NFToken, ERC721Metadata {
/**
* @dev A descriptive name for a collection of NFTs.
*/
string internal nftName;
/**
* @dev An abbreviated name for NFTokens.
*/
string internal nftSymbol;
/**
* @dev Mapping from NFT ID to metadata uri.
*/
mapping(uint256 => string) internal idToUri;
/**
* @notice When implementing this contract don't forget to set nftName and nftSymbol.
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x5b5e139f] = true; // ERC721Metadata
}
/**
* @dev Returns a descriptive name for a collection of NFTokens.
* @return _name Representing name.
*/
function name() external view override returns (string memory _name) {
_name = nftName;
}
/**
* @dev Returns an abbreviated name for NFTokens.
* @return _symbol Representing symbol.
*/
function symbol() external view override returns (string memory _symbol) {
_symbol = nftSymbol;
}
/**
* @dev A distinct URI (RFC 3986) for a given NFT.
* @param _tokenId Id for which we want uri.
* @return URI of _tokenId.
*/
function tokenURI(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (string memory)
{
return idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* burn function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual override {
super._burn(_tokenId);
delete idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Set a distinct URI (RFC 3986) for a given NFT ID.
* @param _tokenId Id for which we want URI.
* @param _uri String representing RFC 3986 URI.
*/
function _setTokenUri(uint256 _tokenId, string memory _uri)
internal
validNFToken(_tokenId)
{
idToUri[_tokenId] = _uri;
}
} | /**
* @dev Optional metadata implementation for ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | tokenURI | function tokenURI(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (string memory)
{
return idToUri[_tokenId];
}
| /**
* @dev A distinct URI (RFC 3986) for a given NFT.
* @param _tokenId Id for which we want uri.
* @return URI of _tokenId.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
1257,
1461
]
} | 9,661 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFTokenMetadata | contract NFTokenMetadata is NFToken, ERC721Metadata {
/**
* @dev A descriptive name for a collection of NFTs.
*/
string internal nftName;
/**
* @dev An abbreviated name for NFTokens.
*/
string internal nftSymbol;
/**
* @dev Mapping from NFT ID to metadata uri.
*/
mapping(uint256 => string) internal idToUri;
/**
* @notice When implementing this contract don't forget to set nftName and nftSymbol.
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x5b5e139f] = true; // ERC721Metadata
}
/**
* @dev Returns a descriptive name for a collection of NFTokens.
* @return _name Representing name.
*/
function name() external view override returns (string memory _name) {
_name = nftName;
}
/**
* @dev Returns an abbreviated name for NFTokens.
* @return _symbol Representing symbol.
*/
function symbol() external view override returns (string memory _symbol) {
_symbol = nftSymbol;
}
/**
* @dev A distinct URI (RFC 3986) for a given NFT.
* @param _tokenId Id for which we want uri.
* @return URI of _tokenId.
*/
function tokenURI(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (string memory)
{
return idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* burn function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual override {
super._burn(_tokenId);
delete idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Set a distinct URI (RFC 3986) for a given NFT ID.
* @param _tokenId Id for which we want URI.
* @param _uri String representing RFC 3986 URI.
*/
function _setTokenUri(uint256 _tokenId, string memory _uri)
internal
validNFToken(_tokenId)
{
idToUri[_tokenId] = _uri;
}
} | /**
* @dev Optional metadata implementation for ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _burn | function _burn(uint256 _tokenId) internal virtual override {
super._burn(_tokenId);
delete idToUri[_tokenId];
}
| /**
* @notice This is an internal function which should be called from user-implemented external
* burn function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
1877,
2018
]
} | 9,662 |
NFT | NFT.sol | 0xc356bc60af6546fe036ba0d56fe758b9e5cd4922 | Solidity | NFTokenMetadata | contract NFTokenMetadata is NFToken, ERC721Metadata {
/**
* @dev A descriptive name for a collection of NFTs.
*/
string internal nftName;
/**
* @dev An abbreviated name for NFTokens.
*/
string internal nftSymbol;
/**
* @dev Mapping from NFT ID to metadata uri.
*/
mapping(uint256 => string) internal idToUri;
/**
* @notice When implementing this contract don't forget to set nftName and nftSymbol.
* @dev Contract constructor.
*/
constructor() {
supportedInterfaces[0x5b5e139f] = true; // ERC721Metadata
}
/**
* @dev Returns a descriptive name for a collection of NFTokens.
* @return _name Representing name.
*/
function name() external view override returns (string memory _name) {
_name = nftName;
}
/**
* @dev Returns an abbreviated name for NFTokens.
* @return _symbol Representing symbol.
*/
function symbol() external view override returns (string memory _symbol) {
_symbol = nftSymbol;
}
/**
* @dev A distinct URI (RFC 3986) for a given NFT.
* @param _tokenId Id for which we want uri.
* @return URI of _tokenId.
*/
function tokenURI(uint256 _tokenId)
external
view
override
validNFToken(_tokenId)
returns (string memory)
{
return idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* burn function. Its purpose is to show and properly initialize data structures when using this
* implementation. Also, note that this burn implementation allows the minter to re-mint a burned
* NFT.
* @dev Burns a NFT.
* @param _tokenId ID of the NFT to be burned.
*/
function _burn(uint256 _tokenId) internal virtual override {
super._burn(_tokenId);
delete idToUri[_tokenId];
}
/**
* @notice This is an internal function which should be called from user-implemented external
* function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Set a distinct URI (RFC 3986) for a given NFT ID.
* @param _tokenId Id for which we want URI.
* @param _uri String representing RFC 3986 URI.
*/
function _setTokenUri(uint256 _tokenId, string memory _uri)
internal
validNFToken(_tokenId)
{
idToUri[_tokenId] = _uri;
}
} | /**
* @dev Optional metadata implementation for ERC-721 non-fungible token standard.
*/ | NatSpecMultiLine | _setTokenUri | function _setTokenUri(uint256 _tokenId, string memory _uri)
internal
validNFToken(_tokenId)
{
idToUri[_tokenId] = _uri;
}
| /**
* @notice This is an internal function which should be called from user-implemented external
* function. Its purpose is to show and properly initialize data structures when using this
* implementation.
* @dev Set a distinct URI (RFC 3986) for a given NFT ID.
* @param _tokenId Id for which we want URI.
* @param _uri String representing RFC 3986 URI.
*/ | NatSpecMultiLine | v0.8.6+commit.11564f7e | MIT | ipfs://36b35c4795538aa6f1ec715fd1d4491538b32e1f1e2adfe185defc55cf321d08 | {
"func_code_index": [
2426,
2589
]
} | 9,663 |
FinanceChain | FinanceChain.sol | 0x743309636fd55e2afe1b53d0eee8c34defad7a06 | Solidity | FinanceChain | contract FinanceChain {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function FinanceChain(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
} | FinanceChain | function FinanceChain(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
| /**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/ | NatSpecMultiLine | v0.4.16+commit.d7661dd9 | bzzr://eb8786d682d99c6a3ed2e118db76d9c21919dde1dfc665df67294e026cbe205e | {
"func_code_index": [
843,
1390
]
} | 9,664 |
|||
FinanceChain | FinanceChain.sol | 0x743309636fd55e2afe1b53d0eee8c34defad7a06 | Solidity | FinanceChain | contract FinanceChain {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function FinanceChain(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
} | _transfer | function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
| /**
* Internal transfer, only can be called by this contract
*/ | NatSpecMultiLine | v0.4.16+commit.d7661dd9 | bzzr://eb8786d682d99c6a3ed2e118db76d9c21919dde1dfc665df67294e026cbe205e | {
"func_code_index": [
1474,
2316
]
} | 9,665 |
|||
FinanceChain | FinanceChain.sol | 0x743309636fd55e2afe1b53d0eee8c34defad7a06 | Solidity | FinanceChain | contract FinanceChain {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function FinanceChain(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
} | transfer | function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
| /**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/ | NatSpecMultiLine | v0.4.16+commit.d7661dd9 | bzzr://eb8786d682d99c6a3ed2e118db76d9c21919dde1dfc665df67294e026cbe205e | {
"func_code_index": [
2522,
2634
]
} | 9,666 |
|||
FinanceChain | FinanceChain.sol | 0x743309636fd55e2afe1b53d0eee8c34defad7a06 | Solidity | FinanceChain | contract FinanceChain {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function FinanceChain(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
| /**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/ | NatSpecMultiLine | v0.4.16+commit.d7661dd9 | bzzr://eb8786d682d99c6a3ed2e118db76d9c21919dde1dfc665df67294e026cbe205e | {
"func_code_index": [
2909,
3210
]
} | 9,667 |
|||
FinanceChain | FinanceChain.sol | 0x743309636fd55e2afe1b53d0eee8c34defad7a06 | Solidity | FinanceChain | contract FinanceChain {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function FinanceChain(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
} | approve | function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
| /**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/ | NatSpecMultiLine | v0.4.16+commit.d7661dd9 | bzzr://eb8786d682d99c6a3ed2e118db76d9c21919dde1dfc665df67294e026cbe205e | {
"func_code_index": [
3474,
3650
]
} | 9,668 |
|||
FinanceChain | FinanceChain.sol | 0x743309636fd55e2afe1b53d0eee8c34defad7a06 | Solidity | FinanceChain | contract FinanceChain {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function FinanceChain(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
} | approveAndCall | function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
| /**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/ | NatSpecMultiLine | v0.4.16+commit.d7661dd9 | bzzr://eb8786d682d99c6a3ed2e118db76d9c21919dde1dfc665df67294e026cbe205e | {
"func_code_index": [
4044,
4396
]
} | 9,669 |
|||
FinanceChain | FinanceChain.sol | 0x743309636fd55e2afe1b53d0eee8c34defad7a06 | Solidity | FinanceChain | contract FinanceChain {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function FinanceChain(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
} | burn | function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
| /**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/ | NatSpecMultiLine | v0.4.16+commit.d7661dd9 | bzzr://eb8786d682d99c6a3ed2e118db76d9c21919dde1dfc665df67294e026cbe205e | {
"func_code_index": [
4566,
4940
]
} | 9,670 |
|||
FinanceChain | FinanceChain.sol | 0x743309636fd55e2afe1b53d0eee8c34defad7a06 | Solidity | FinanceChain | contract FinanceChain {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function FinanceChain(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
} | burnFrom | function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
Burn(_from, _value);
return true;
}
| /**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/ | NatSpecMultiLine | v0.4.16+commit.d7661dd9 | bzzr://eb8786d682d99c6a3ed2e118db76d9c21919dde1dfc665df67294e026cbe205e | {
"func_code_index": [
5198,
5809
]
} | 9,671 |
|||
SimpleToken | ERC20Detailed.sol | 0xd56ae7e69fccdaa21e6cc5b1c3ff19f66f4e841b | 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: 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.1+commit.c8a2cb62 | MIT | bzzr://27a2eb5a6294b610c7c4c8ed2bc6ea811fe9823a2e8b7c461b82ac0ee7e07f92 | {
"func_code_index": [
550,
638
]
} | 9,672 |
SimpleToken | ERC20Detailed.sol | 0xd56ae7e69fccdaa21e6cc5b1c3ff19f66f4e841b | 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: 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.1+commit.c8a2cb62 | MIT | bzzr://27a2eb5a6294b610c7c4c8ed2bc6ea811fe9823a2e8b7c461b82ac0ee7e07f92 | {
"func_code_index": [
752,
844
]
} | 9,673 |
SimpleToken | ERC20Detailed.sol | 0xd56ae7e69fccdaa21e6cc5b1c3ff19f66f4e841b | 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: 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: 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.1+commit.c8a2cb62 | MIT | bzzr://27a2eb5a6294b610c7c4c8ed2bc6ea811fe9823a2e8b7c461b82ac0ee7e07f92 | {
"func_code_index": [
1402,
1490
]
} | 9,674 |
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | pause | function pause() external onlyOwner {
_pause();
}
| /**
* @notice pause staking, unstaking and claiming rewards
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
1458,
1523
]
} | 9,675 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | unpause | function unpause() external onlyOwner {
_unpause();
}
| /**
* @notice unpause staking, unstaking and claiming rewards
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
1602,
1678
]
} | 9,676 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | setRewardsPerBlock | function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
| /**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
1797,
2156
]
} | 9,677 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | setLockupPeriod | function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
| /**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
2367,
2537
]
} | 9,678 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | withdraw | function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
| /**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
2718,
2958
]
} | 9,679 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | stake | function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
| /**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
3082,
3739
]
} | 9,680 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | unstake | function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
| /**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
3866,
4860
]
} | 9,681 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | exitWithoutRewards | function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
| /**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
4989,
5657
]
} | 9,682 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | claimRewards | function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
| /**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
5778,
6600
]
} | 9,683 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | calculateRewardsByAccount | function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
| /**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
6750,
7047
]
} | 9,684 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | calculateRewards | function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
| /**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
7173,
8173
]
} | 9,685 |
||
ComicStaking | contracts/ComicStaking.sol | 0x2db69d45771055f95050a8530add756264109ac5 | Solidity | ComicStaking | contract ComicStaking is Ownable, IERC721Receiver, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.UintSet;
IERC20 public immutable rewardToken;
IERC721 public immutable stakedTokenContract;
uint256 constant MAX_REWARD_CHANGES = 2000;
uint128 public rewardPerBlock;
uint128 public lockupPeriod = 2592000; // 30 days
struct Stake {
uint128 lockupExpires;
uint128 lastClaimedBlock;
}
struct RewardChanged {
uint128 block;
uint128 rewardPerBlock;
}
RewardChanged[] rewardChanges;
event Staked(address indexed account, uint256[] tokenIds);
event Unstaked(address indexed account, uint256[] tokenIds);
event RewardsClaimed(address indexed account, uint256 amount);
event RewardsChanged(uint128 indexed rewardPerBlock);
event LockupPeriodChanged(uint128 indexed lockupPeriod);
mapping(uint256 => Stake) public stakes;
mapping(address => EnumerableSet.UintSet) private stakedTokens;
constructor(address _rewardTokenContract, address _stakedTokenContract, uint128 _rewardPerBlock) {
rewardToken = IERC20(_rewardTokenContract);
stakedTokenContract = IERC721(_stakedTokenContract);
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
}
/**
* @notice pause staking, unstaking and claiming rewards
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice unpause staking, unstaking and claiming rewards
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice set ERC20 reward amount per block
*
* @param _rewardPerBlock the reward amount
*/
function setRewardsPerBlock(uint128 _rewardPerBlock) external onlyOwner {
require(rewardChanges.length < MAX_REWARD_CHANGES, "Set rewards: Max reward changes reached");
rewardPerBlock = _rewardPerBlock;
rewardChanges.push(RewardChanged(uint128(block.number), _rewardPerBlock));
emit RewardsChanged(_rewardPerBlock);
}
/**
* @notice set lockup period in seconds.
* unstaking or claiming rewards not allowed until lockup period expired
*
* @param _lockupPeriod length of the lockup period in seconds
*/
function setLockupPeriod(uint128 _lockupPeriod) external onlyOwner {
lockupPeriod = _lockupPeriod;
emit LockupPeriodChanged(_lockupPeriod);
}
/**
* @notice withdraw reward tokens owned by staking contract
*
* @param to the token ids to unstake
* @param amount the amount of tokens to withdraw
*/
function withdraw(address to, uint256 amount) external onlyOwner {
require(
rewardToken.balanceOf(address(this)) >= amount,
"Withdraw: balance exceeded");
rewardToken.transfer(to, amount);
}
/**
* @notice stake given token ids for specified user
*
* @param tokenIds the token ids to stake
*/
function stake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Stake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(stakedTokenContract.ownerOf(tokenIds[i]) == msg.sender, "Stake: sender not owner");
stakedTokenContract.safeTransferFrom(msg.sender, address(this), tokenIds[i]);
stakes[tokenIds[i]] = Stake(uint128(block.timestamp + lockupPeriod), uint128(block.number));
stakedTokens[msg.sender].add(tokenIds[i]);
}
emit Staked(msg.sender, tokenIds);
}
/**
* @notice unstake given token ids and claim rewards
*
* @param tokenIds the token ids to unstake
*/
function unstake(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"Unstake: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
rewardToken.transfer(msg.sender, rewards);
emit Unstaked(msg.sender, tokenIds);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice unstake given token ids and forfeit rewards
*
* @param tokenIds the token ids to unstake
*/
function exitWithoutRewards(uint256[] calldata tokenIds) external whenNotPaused nonReentrant {
require(tokenIds.length <= 40 && tokenIds.length > 0, "Unstake: amount prohibited");
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"Unstake: token not staked"
);
stakedTokens[msg.sender].remove(tokenIds[i]);
delete stakes[tokenIds[i]];
stakedTokenContract.safeTransferFrom(address(this), msg.sender, tokenIds[i]);
}
emit Unstaked(msg.sender, tokenIds);
}
/**
* @notice claim rewards for given token ids
*
* @param tokenIds the token ids to claim for
*/
function claimRewards(uint256[] calldata tokenIds) external whenNotPaused {
require(tokenIds.length > 0, "ClaimRewards: missing token ids");
uint256 rewards;
for (uint256 i; i < tokenIds.length; i++) {
require(
stakedTokens[msg.sender].contains(tokenIds[i]),
"ClaimRewards: token not staked"
);
require(
stakes[tokenIds[i]].lockupExpires < block.timestamp,
"ClaimRewards: lockup period not expired"
);
rewards += calculateRewards(tokenIds[i]);
stakes[tokenIds[i]].lastClaimedBlock = uint128(block.number);
}
rewardToken.transfer(msg.sender, rewards);
emit RewardsClaimed(msg.sender, rewards);
}
/**
* @notice calculate rewards for all staken token ids of a given account
*
* @param account the account to calculate for
*/
function calculateRewardsByAccount(address account) external view returns (uint256) {
uint256 rewards;
for (uint256 i; i < stakedTokens[account].length(); i++) {
rewards += calculateRewards(stakedTokens[account].at(i));
}
return rewards;
}
/**
* @notice calculate rewards for given token id
*
* @param tokenID the token id to calculate for
*/
function calculateRewards(uint256 tokenID) public view returns (uint256) {
require(stakes[tokenID].lastClaimedBlock != 0, "token not staked");
uint256 rewards;
uint256 blocksPassed;
uint128 lastClaimedBlock = stakes[tokenID].lastClaimedBlock;
uint256 from;
uint256 last;
for(uint256 i=0; i < rewardChanges.length; i++) {
bool hasNext = i+1 < rewardChanges.length;
from = rewardChanges[i].block >= lastClaimedBlock ?
rewardChanges[i].block :
lastClaimedBlock;
last = hasNext ?
(rewardChanges[i+1].block >= lastClaimedBlock ?
rewardChanges[i+1].block :
from
) :
block.number;
blocksPassed = last - from;
rewards += rewardChanges[i].rewardPerBlock * blocksPassed;
}
return rewards;
}
/**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/
function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
function onERC721Received(address operator, address, uint256, bytes memory) public view override returns (bytes4) {
require(operator == address(this), "Operator not staking contract");
return this.onERC721Received.selector;
}
} | /*
* @title Staking for Pixelvault ERC721 tokens
*
* @author Niftydude
*/ | Comment | stakedTokensOf | function stakedTokensOf(address account) external view returns (uint256[] memory) {
uint256[] memory tokenIds = new uint256[](stakedTokens[account].length());
for (uint256 i; i < tokenIds.length; i++) {
tokenIds[i] = stakedTokens[account].at(i);
}
return tokenIds;
}
| /**
* @notice return all staked token ids for a given account
*
* @param account the account to return token ids for
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | {
"func_code_index": [
8316,
8628
]
} | 9,686 |
||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | ERC20 | contract ERC20 {
/* 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;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance);
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | balanceOf | function balanceOf(address _owner) constant returns (uint256 balance);
| /// @param _owner The address from which the balance will be retrieved
/// @return The balance | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
631,
706
]
} | 9,687 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | ERC20 | contract ERC20 {
/* 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;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance);
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | transfer | function transfer(address _to, uint256 _value) returns (bool success);
| /// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
943,
1018
]
} | 9,688 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | ERC20 | contract ERC20 {
/* 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;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance);
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
| /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
1341,
1435
]
} | 9,689 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | ERC20 | contract ERC20 {
/* 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;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance);
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | approve | function approve(address _spender, uint256 _value) returns (bool success);
| /// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
1725,
1804
]
} | 9,690 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | ERC20 | contract ERC20 {
/* 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;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance);
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | allowance | function allowance(address _owner, address _spender) constant returns (uint256 remaining);
| /// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
2012,
2107
]
} | 9,691 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | StandardToken | contract StandardToken is ERC20, SafeMath {
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
/// @dev Returns number of tokens owned by given address.
/// @param _owner Address of token owner.
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success.
/// @param _to Address of token receiver.
/// @param _value Number of tokens to transfer.
function transfer(address _to, uint256 _value) returns (bool) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] = safeSub(balances[msg.sender], _value);
balances[_to] = safeAdd(balances[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
} else return false;
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address from where tokens are withdrawn.
/// @param _to Address to where tokens are sent.
/// @param _value Number of tokens to transfer.
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] = safeAdd(balances[_to], _value);
balances[_from] = safeSub(balances[_from], _value);
allowed[_from][msg.sender] = safeSub(allowed[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
} else return false;
}
/// @dev Sets approved amount of tokens for spender. Returns success.
/// @param _spender Address of allowed account.
/// @param _value Number of approved tokens.
function approve(address _spender, uint256 _value) returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/// @dev Returns number of allowed tokens for given address.
/// @param _owner Address of token owner.
/// @param _spender Address of token spender.
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
} | balanceOf | function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
| /// @dev Returns number of tokens owned by given address.
/// @param _owner Address of token owner. | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
264,
381
]
} | 9,692 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | StandardToken | contract StandardToken is ERC20, SafeMath {
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
/// @dev Returns number of tokens owned by given address.
/// @param _owner Address of token owner.
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success.
/// @param _to Address of token receiver.
/// @param _value Number of tokens to transfer.
function transfer(address _to, uint256 _value) returns (bool) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] = safeSub(balances[msg.sender], _value);
balances[_to] = safeAdd(balances[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
} else return false;
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address from where tokens are withdrawn.
/// @param _to Address to where tokens are sent.
/// @param _value Number of tokens to transfer.
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] = safeAdd(balances[_to], _value);
balances[_from] = safeSub(balances[_from], _value);
allowed[_from][msg.sender] = safeSub(allowed[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
} else return false;
}
/// @dev Sets approved amount of tokens for spender. Returns success.
/// @param _spender Address of allowed account.
/// @param _value Number of approved tokens.
function approve(address _spender, uint256 _value) returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/// @dev Returns number of allowed tokens for given address.
/// @param _owner Address of token owner.
/// @param _spender Address of token spender.
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
} | transfer | function transfer(address _to, uint256 _value) returns (bool) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] = safeSub(balances[msg.sender], _value);
balances[_to] = safeAdd(balances[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
} else return false;
}
| /// @dev Transfers sender's tokens to a given address. Returns success.
/// @param _to Address of token receiver.
/// @param _value Number of tokens to transfer. | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
561,
937
]
} | 9,693 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | StandardToken | contract StandardToken is ERC20, SafeMath {
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
/// @dev Returns number of tokens owned by given address.
/// @param _owner Address of token owner.
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success.
/// @param _to Address of token receiver.
/// @param _value Number of tokens to transfer.
function transfer(address _to, uint256 _value) returns (bool) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] = safeSub(balances[msg.sender], _value);
balances[_to] = safeAdd(balances[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
} else return false;
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address from where tokens are withdrawn.
/// @param _to Address to where tokens are sent.
/// @param _value Number of tokens to transfer.
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] = safeAdd(balances[_to], _value);
balances[_from] = safeSub(balances[_from], _value);
allowed[_from][msg.sender] = safeSub(allowed[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
} else return false;
}
/// @dev Sets approved amount of tokens for spender. Returns success.
/// @param _spender Address of allowed account.
/// @param _value Number of approved tokens.
function approve(address _spender, uint256 _value) returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/// @dev Returns number of allowed tokens for given address.
/// @param _owner Address of token owner.
/// @param _spender Address of token spender.
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] = safeAdd(balances[_to], _value);
balances[_from] = safeSub(balances[_from], _value);
allowed[_from][msg.sender] = safeSub(allowed[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
} else return false;
}
| /// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address from where tokens are withdrawn.
/// @param _to Address to where tokens are sent.
/// @param _value Number of tokens to transfer. | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
1216,
1718
]
} | 9,694 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | StandardToken | contract StandardToken is ERC20, SafeMath {
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
/// @dev Returns number of tokens owned by given address.
/// @param _owner Address of token owner.
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success.
/// @param _to Address of token receiver.
/// @param _value Number of tokens to transfer.
function transfer(address _to, uint256 _value) returns (bool) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] = safeSub(balances[msg.sender], _value);
balances[_to] = safeAdd(balances[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
} else return false;
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address from where tokens are withdrawn.
/// @param _to Address to where tokens are sent.
/// @param _value Number of tokens to transfer.
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] = safeAdd(balances[_to], _value);
balances[_from] = safeSub(balances[_from], _value);
allowed[_from][msg.sender] = safeSub(allowed[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
} else return false;
}
/// @dev Sets approved amount of tokens for spender. Returns success.
/// @param _spender Address of allowed account.
/// @param _value Number of approved tokens.
function approve(address _spender, uint256 _value) returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/// @dev Returns number of allowed tokens for given address.
/// @param _owner Address of token owner.
/// @param _spender Address of token spender.
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
} | approve | function approve(address _spender, uint256 _value) returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
| /// @dev Sets approved amount of tokens for spender. Returns success.
/// @param _spender Address of allowed account.
/// @param _value Number of approved tokens. | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
1899,
2098
]
} | 9,695 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | StandardToken | contract StandardToken is ERC20, SafeMath {
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
/// @dev Returns number of tokens owned by given address.
/// @param _owner Address of token owner.
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success.
/// @param _to Address of token receiver.
/// @param _value Number of tokens to transfer.
function transfer(address _to, uint256 _value) returns (bool) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] = safeSub(balances[msg.sender], _value);
balances[_to] = safeAdd(balances[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
} else return false;
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address from where tokens are withdrawn.
/// @param _to Address to where tokens are sent.
/// @param _value Number of tokens to transfer.
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] = safeAdd(balances[_to], _value);
balances[_from] = safeSub(balances[_from], _value);
allowed[_from][msg.sender] = safeSub(allowed[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
} else return false;
}
/// @dev Sets approved amount of tokens for spender. Returns success.
/// @param _spender Address of allowed account.
/// @param _value Number of approved tokens.
function approve(address _spender, uint256 _value) returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/// @dev Returns number of allowed tokens for given address.
/// @param _owner Address of token owner.
/// @param _spender Address of token spender.
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
} | allowance | function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
| /// @dev Returns number of allowed tokens for given address.
/// @param _owner Address of token owner.
/// @param _spender Address of token spender. | NatSpecSingleLine | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
2265,
2411
]
} | 9,696 |
|||
BsToken_SNOV | BsToken_SNOV.sol | 0x38bca9e1cebc427d31118d1665cbf0e8e8304083 | Solidity | BsToken | contract BsToken is StandardToken, MultiOwnable {
bool public locked;
string public name;
string public symbol;
uint256 public totalSupply;
uint8 public decimals = 18;
string public version = 'v0.1';
address public creator;
address public seller;
uint256 public tokensSold;
uint256 public totalSales;
event Sell(address indexed seller, address indexed buyer, uint256 value);
event SellerChanged(address indexed oldSeller, address indexed newSeller);
modifier onlyUnlocked() {
if (!isOwner(msg.sender) && locked) throw;
_;
}
function BsToken(string _name, string _symbol, uint256 _totalSupply, address _seller) MultiOwnable() {
creator = msg.sender;
seller = _seller;
name = _name;
symbol = _symbol;
totalSupply = _totalSupply;
balances[seller] = totalSupply;
}
function changeSeller(address newSeller) onlyOwner returns (bool) {
if (newSeller == 0x0 || seller == newSeller) throw;
address oldSeller = seller;
uint256 unsoldTokens = balances[oldSeller];
balances[oldSeller] = 0;
balances[newSeller] = safeAdd(balances[newSeller], unsoldTokens);
seller = newSeller;
SellerChanged(oldSeller, newSeller);
return true;
}
function sell(address _to, uint256 _value) onlyOwner returns (bool) {
if (balances[seller] >= _value && _value > 0) {
balances[seller] = safeSub(balances[seller], _value);
balances[_to] = safeAdd(balances[_to], _value);
tokensSold = safeAdd(tokensSold, _value);
totalSales = safeAdd(totalSales, 1);
Sell(seller, _to, _value);
return true;
} else return false;
}
function transfer(address _to, uint256 _value) onlyUnlocked returns (bool) {
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) onlyUnlocked returns (bool) {
return super.transferFrom(_from, _to, _value);
}
function lock() onlyOwner {
locked = true;
}
function unlock() onlyOwner {
locked = false;
}
function burn(uint256 _value) returns (bool) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] = safeSub(balances[msg.sender], _value) ;
totalSupply = safeSub(totalSupply, _value);
Transfer(msg.sender, 0x0, _value);
return true;
} else return false;
}
/* Approve and then communicate the approved contract in a single tx */
function approveAndCall(address _spender, uint256 _value) {
TokenSpender spender = TokenSpender(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value);
}
}
} | approveAndCall | function approveAndCall(address _spender, uint256 _value) {
TokenSpender spender = TokenSpender(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value);
}
}
| /* Approve and then communicate the approved contract in a single tx */ | Comment | v0.4.11+commit.68ef5810 | bzzr://b0ff219b13198d2f30f7c5419e4ed879b135f575c6c5f254031e8b6a64d0dc8e | {
"func_code_index": [
2720,
2958
]
} | 9,697 |
|||
JBFFinance | JBFFinance.sol | 0xb33e9b045e789e4381adcaafa3310402cf660055 | Solidity | JBFFinance | contract JBFFinance is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "JBF";
name = "JBF Finance";
decimals = 18;
_totalSupply = 26999000000000000000000;
balances[0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd] = _totalSupply;
emit Transfer(address(0), 0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | totalSupply | function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
| // ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | None | bzzr://77f5dafbc79ce30e58dd19cf5918d319d6e4fb52e17a040a18d25f0dc4c87579 | {
"func_code_index": [
980,
1101
]
} | 9,698 |
JBFFinance | JBFFinance.sol | 0xb33e9b045e789e4381adcaafa3310402cf660055 | Solidity | JBFFinance | contract JBFFinance is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "JBF";
name = "JBF Finance";
decimals = 18;
_totalSupply = 26999000000000000000000;
balances[0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd] = _totalSupply;
emit Transfer(address(0), 0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | balanceOf | function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
| // ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | None | bzzr://77f5dafbc79ce30e58dd19cf5918d319d6e4fb52e17a040a18d25f0dc4c87579 | {
"func_code_index": [
1321,
1450
]
} | 9,699 |
JBFFinance | JBFFinance.sol | 0xb33e9b045e789e4381adcaafa3310402cf660055 | Solidity | JBFFinance | contract JBFFinance is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "JBF";
name = "JBF Finance";
decimals = 18;
_totalSupply = 26999000000000000000000;
balances[0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd] = _totalSupply;
emit Transfer(address(0), 0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | transfer | function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | None | bzzr://77f5dafbc79ce30e58dd19cf5918d319d6e4fb52e17a040a18d25f0dc4c87579 | {
"func_code_index": [
1794,
2076
]
} | 9,700 |
JBFFinance | JBFFinance.sol | 0xb33e9b045e789e4381adcaafa3310402cf660055 | Solidity | JBFFinance | contract JBFFinance is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "JBF";
name = "JBF Finance";
decimals = 18;
_totalSupply = 26999000000000000000000;
balances[0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd] = _totalSupply;
emit Transfer(address(0), 0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | approve | function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | None | bzzr://77f5dafbc79ce30e58dd19cf5918d319d6e4fb52e17a040a18d25f0dc4c87579 | {
"func_code_index": [
2584,
2797
]
} | 9,701 |
JBFFinance | JBFFinance.sol | 0xb33e9b045e789e4381adcaafa3310402cf660055 | Solidity | JBFFinance | contract JBFFinance is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "JBF";
name = "JBF Finance";
decimals = 18;
_totalSupply = 26999000000000000000000;
balances[0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd] = _totalSupply;
emit Transfer(address(0), 0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | transferFrom | function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | None | bzzr://77f5dafbc79ce30e58dd19cf5918d319d6e4fb52e17a040a18d25f0dc4c87579 | {
"func_code_index": [
3328,
3691
]
} | 9,702 |
JBFFinance | JBFFinance.sol | 0xb33e9b045e789e4381adcaafa3310402cf660055 | Solidity | JBFFinance | contract JBFFinance is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "JBF";
name = "JBF Finance";
decimals = 18;
_totalSupply = 26999000000000000000000;
balances[0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd] = _totalSupply;
emit Transfer(address(0), 0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | allowance | function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
| // ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | None | bzzr://77f5dafbc79ce30e58dd19cf5918d319d6e4fb52e17a040a18d25f0dc4c87579 | {
"func_code_index": [
3974,
4130
]
} | 9,703 |
JBFFinance | JBFFinance.sol | 0xb33e9b045e789e4381adcaafa3310402cf660055 | Solidity | JBFFinance | contract JBFFinance is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "JBF";
name = "JBF Finance";
decimals = 18;
_totalSupply = 26999000000000000000000;
balances[0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd] = _totalSupply;
emit Transfer(address(0), 0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | approveAndCall | function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | None | bzzr://77f5dafbc79ce30e58dd19cf5918d319d6e4fb52e17a040a18d25f0dc4c87579 | {
"func_code_index": [
4485,
4807
]
} | 9,704 |
JBFFinance | JBFFinance.sol | 0xb33e9b045e789e4381adcaafa3310402cf660055 | Solidity | JBFFinance | contract JBFFinance is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "JBF";
name = "JBF Finance";
decimals = 18;
_totalSupply = 26999000000000000000000;
balances[0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd] = _totalSupply;
emit Transfer(address(0), 0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | function () public payable {
revert();
}
| // ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | None | bzzr://77f5dafbc79ce30e58dd19cf5918d319d6e4fb52e17a040a18d25f0dc4c87579 | {
"func_code_index": [
4999,
5058
]
} | 9,705 |
|
JBFFinance | JBFFinance.sol | 0xb33e9b045e789e4381adcaafa3310402cf660055 | Solidity | JBFFinance | contract JBFFinance is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "JBF";
name = "JBF Finance";
decimals = 18;
_totalSupply = 26999000000000000000000;
balances[0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd] = _totalSupply;
emit Transfer(address(0), 0xAD833a3fbcF61d2d35b88cCACA6FE30c4dB48ccd, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | transferAnyERC20Token | function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
| // ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | None | bzzr://77f5dafbc79ce30e58dd19cf5918d319d6e4fb52e17a040a18d25f0dc4c87579 | {
"func_code_index": [
5291,
5480
]
} | 9,706 |