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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SaveWrapper | SaveWrapper.sol | 0xd082363752d08c54ab47c248fd5a11f8ee634bb9 | Solidity | SaveWrapper | contract SaveWrapper is Ownable {
using SafeERC20 for IERC20;
/**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/
function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
/**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/
function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/
function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/
function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
/** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/
function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
/** @dev Internal func to get estimated Uniswap output from WETH to token trade */
function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
/**
* @dev Approve mAsset, Save and multiple bAssets
*/
function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
/**
* @dev Approve one token/spender
*/
function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
/**
* @dev Approve multiple tokens/one spender
*/
function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
function _approve(address _token, address _spender) internal {
require(_spender != address(0), "Invalid spender");
require(_token != address(0), "Invalid token");
IERC20(_token).safeApprove(_spender, 2**256 - 1);
}
function _approve(address[] calldata _tokens, address _spender) internal {
require(_spender != address(0), "Invalid spender");
for (uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token");
IERC20(_tokens[i]).safeApprove(_spender, 2**256 - 1);
}
}
} | // 3 FLOWS
// 0 - SAVE
// 1 - MINT AND SAVE
// 2 - BUY AND SAVE (ETH via Uni) | LineComment | saveAndStake | function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
| /**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/ | NatSpecMultiLine | v0.8.2+commit.661d1103 | MIT | ipfs://41f8902acf27ffe8ff89ce6a7ba9aa9a5d6e95217982e5456b7a917e0bf3b42a | {
"func_code_index": [
347,
886
]
} | 56,661 |
SaveWrapper | SaveWrapper.sol | 0xd082363752d08c54ab47c248fd5a11f8ee634bb9 | Solidity | SaveWrapper | contract SaveWrapper is Ownable {
using SafeERC20 for IERC20;
/**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/
function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
/**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/
function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/
function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/
function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
/** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/
function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
/** @dev Internal func to get estimated Uniswap output from WETH to token trade */
function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
/**
* @dev Approve mAsset, Save and multiple bAssets
*/
function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
/**
* @dev Approve one token/spender
*/
function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
/**
* @dev Approve multiple tokens/one spender
*/
function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
function _approve(address _token, address _spender) internal {
require(_spender != address(0), "Invalid spender");
require(_token != address(0), "Invalid token");
IERC20(_token).safeApprove(_spender, 2**256 - 1);
}
function _approve(address[] calldata _tokens, address _spender) internal {
require(_spender != address(0), "Invalid spender");
for (uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token");
IERC20(_tokens[i]).safeApprove(_spender, 2**256 - 1);
}
}
} | // 3 FLOWS
// 0 - SAVE
// 1 - MINT AND SAVE
// 2 - BUY AND SAVE (ETH via Uni) | LineComment | saveViaMint | function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
| /**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/ | NatSpecMultiLine | v0.8.2+commit.661d1103 | MIT | ipfs://41f8902acf27ffe8ff89ce6a7ba9aa9a5d6e95217982e5456b7a917e0bf3b42a | {
"func_code_index": [
1350,
2160
]
} | 56,662 |
SaveWrapper | SaveWrapper.sol | 0xd082363752d08c54ab47c248fd5a11f8ee634bb9 | Solidity | SaveWrapper | contract SaveWrapper is Ownable {
using SafeERC20 for IERC20;
/**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/
function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
/**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/
function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/
function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/
function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
/** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/
function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
/** @dev Internal func to get estimated Uniswap output from WETH to token trade */
function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
/**
* @dev Approve mAsset, Save and multiple bAssets
*/
function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
/**
* @dev Approve one token/spender
*/
function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
/**
* @dev Approve multiple tokens/one spender
*/
function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
function _approve(address _token, address _spender) internal {
require(_spender != address(0), "Invalid spender");
require(_token != address(0), "Invalid token");
IERC20(_token).safeApprove(_spender, 2**256 - 1);
}
function _approve(address[] calldata _tokens, address _spender) internal {
require(_spender != address(0), "Invalid spender");
for (uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token");
IERC20(_tokens[i]).safeApprove(_spender, 2**256 - 1);
}
}
} | // 3 FLOWS
// 0 - SAVE
// 1 - MINT AND SAVE
// 2 - BUY AND SAVE (ETH via Uni) | LineComment | saveViaUniswapETH | function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
| /**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/ | NatSpecMultiLine | v0.8.2+commit.661d1103 | MIT | ipfs://41f8902acf27ffe8ff89ce6a7ba9aa9a5d6e95217982e5456b7a917e0bf3b42a | {
"func_code_index": [
2793,
4002
]
} | 56,663 |
SaveWrapper | SaveWrapper.sol | 0xd082363752d08c54ab47c248fd5a11f8ee634bb9 | Solidity | SaveWrapper | contract SaveWrapper is Ownable {
using SafeERC20 for IERC20;
/**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/
function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
/**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/
function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/
function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/
function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
/** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/
function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
/** @dev Internal func to get estimated Uniswap output from WETH to token trade */
function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
/**
* @dev Approve mAsset, Save and multiple bAssets
*/
function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
/**
* @dev Approve one token/spender
*/
function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
/**
* @dev Approve multiple tokens/one spender
*/
function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
function _approve(address _token, address _spender) internal {
require(_spender != address(0), "Invalid spender");
require(_token != address(0), "Invalid token");
IERC20(_token).safeApprove(_spender, 2**256 - 1);
}
function _approve(address[] calldata _tokens, address _spender) internal {
require(_spender != address(0), "Invalid spender");
for (uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token");
IERC20(_tokens[i]).safeApprove(_spender, 2**256 - 1);
}
}
} | // 3 FLOWS
// 0 - SAVE
// 1 - MINT AND SAVE
// 2 - BUY AND SAVE (ETH via Uni) | LineComment | estimate_saveViaUniswapETH | function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
| /**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/ | NatSpecMultiLine | v0.8.2+commit.661d1103 | MIT | ipfs://41f8902acf27ffe8ff89ce6a7ba9aa9a5d6e95217982e5456b7a917e0bf3b42a | {
"func_code_index": [
4314,
4814
]
} | 56,664 |
SaveWrapper | SaveWrapper.sol | 0xd082363752d08c54ab47c248fd5a11f8ee634bb9 | Solidity | SaveWrapper | contract SaveWrapper is Ownable {
using SafeERC20 for IERC20;
/**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/
function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
/**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/
function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/
function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/
function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
/** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/
function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
/** @dev Internal func to get estimated Uniswap output from WETH to token trade */
function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
/**
* @dev Approve mAsset, Save and multiple bAssets
*/
function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
/**
* @dev Approve one token/spender
*/
function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
/**
* @dev Approve multiple tokens/one spender
*/
function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
function _approve(address _token, address _spender) internal {
require(_spender != address(0), "Invalid spender");
require(_token != address(0), "Invalid token");
IERC20(_token).safeApprove(_spender, 2**256 - 1);
}
function _approve(address[] calldata _tokens, address _spender) internal {
require(_spender != address(0), "Invalid spender");
for (uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token");
IERC20(_tokens[i]).safeApprove(_spender, 2**256 - 1);
}
}
} | // 3 FLOWS
// 0 - SAVE
// 1 - MINT AND SAVE
// 2 - BUY AND SAVE (ETH via Uni) | LineComment | _saveAndStake | function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
| /** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/ | NatSpecMultiLine | v0.8.2+commit.661d1103 | MIT | ipfs://41f8902acf27ffe8ff89ce6a7ba9aa9a5d6e95217982e5456b7a917e0bf3b42a | {
"func_code_index": [
5121,
5565
]
} | 56,665 |
SaveWrapper | SaveWrapper.sol | 0xd082363752d08c54ab47c248fd5a11f8ee634bb9 | Solidity | SaveWrapper | contract SaveWrapper is Ownable {
using SafeERC20 for IERC20;
/**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/
function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
/**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/
function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/
function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/
function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
/** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/
function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
/** @dev Internal func to get estimated Uniswap output from WETH to token trade */
function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
/**
* @dev Approve mAsset, Save and multiple bAssets
*/
function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
/**
* @dev Approve one token/spender
*/
function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
/**
* @dev Approve multiple tokens/one spender
*/
function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
function _approve(address _token, address _spender) internal {
require(_spender != address(0), "Invalid spender");
require(_token != address(0), "Invalid token");
IERC20(_token).safeApprove(_spender, 2**256 - 1);
}
function _approve(address[] calldata _tokens, address _spender) internal {
require(_spender != address(0), "Invalid spender");
for (uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token");
IERC20(_tokens[i]).safeApprove(_spender, 2**256 - 1);
}
}
} | // 3 FLOWS
// 0 - SAVE
// 1 - MINT AND SAVE
// 2 - BUY AND SAVE (ETH via Uni) | LineComment | _getAmountOut | function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
| /** @dev Internal func to get estimated Uniswap output from WETH to token trade */ | NatSpecMultiLine | v0.8.2+commit.661d1103 | MIT | ipfs://41f8902acf27ffe8ff89ce6a7ba9aa9a5d6e95217982e5456b7a917e0bf3b42a | {
"func_code_index": [
5656,
5971
]
} | 56,666 |
SaveWrapper | SaveWrapper.sol | 0xd082363752d08c54ab47c248fd5a11f8ee634bb9 | Solidity | SaveWrapper | contract SaveWrapper is Ownable {
using SafeERC20 for IERC20;
/**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/
function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
/**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/
function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/
function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/
function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
/** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/
function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
/** @dev Internal func to get estimated Uniswap output from WETH to token trade */
function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
/**
* @dev Approve mAsset, Save and multiple bAssets
*/
function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
/**
* @dev Approve one token/spender
*/
function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
/**
* @dev Approve multiple tokens/one spender
*/
function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
function _approve(address _token, address _spender) internal {
require(_spender != address(0), "Invalid spender");
require(_token != address(0), "Invalid token");
IERC20(_token).safeApprove(_spender, 2**256 - 1);
}
function _approve(address[] calldata _tokens, address _spender) internal {
require(_spender != address(0), "Invalid spender");
for (uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token");
IERC20(_tokens[i]).safeApprove(_spender, 2**256 - 1);
}
}
} | // 3 FLOWS
// 0 - SAVE
// 1 - MINT AND SAVE
// 2 - BUY AND SAVE (ETH via Uni) | LineComment | approve | function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
| /**
* @dev Approve mAsset, Save and multiple bAssets
*/ | NatSpecMultiLine | v0.8.2+commit.661d1103 | MIT | ipfs://41f8902acf27ffe8ff89ce6a7ba9aa9a5d6e95217982e5456b7a917e0bf3b42a | {
"func_code_index": [
6047,
6323
]
} | 56,667 |
SaveWrapper | SaveWrapper.sol | 0xd082363752d08c54ab47c248fd5a11f8ee634bb9 | Solidity | SaveWrapper | contract SaveWrapper is Ownable {
using SafeERC20 for IERC20;
/**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/
function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
/**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/
function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/
function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/
function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
/** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/
function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
/** @dev Internal func to get estimated Uniswap output from WETH to token trade */
function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
/**
* @dev Approve mAsset, Save and multiple bAssets
*/
function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
/**
* @dev Approve one token/spender
*/
function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
/**
* @dev Approve multiple tokens/one spender
*/
function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
function _approve(address _token, address _spender) internal {
require(_spender != address(0), "Invalid spender");
require(_token != address(0), "Invalid token");
IERC20(_token).safeApprove(_spender, 2**256 - 1);
}
function _approve(address[] calldata _tokens, address _spender) internal {
require(_spender != address(0), "Invalid spender");
for (uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token");
IERC20(_tokens[i]).safeApprove(_spender, 2**256 - 1);
}
}
} | // 3 FLOWS
// 0 - SAVE
// 1 - MINT AND SAVE
// 2 - BUY AND SAVE (ETH via Uni) | LineComment | approve | function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
| /**
* @dev Approve one token/spender
*/ | NatSpecMultiLine | v0.8.2+commit.661d1103 | MIT | ipfs://41f8902acf27ffe8ff89ce6a7ba9aa9a5d6e95217982e5456b7a917e0bf3b42a | {
"func_code_index": [
6383,
6503
]
} | 56,668 |
SaveWrapper | SaveWrapper.sol | 0xd082363752d08c54ab47c248fd5a11f8ee634bb9 | Solidity | SaveWrapper | contract SaveWrapper is Ownable {
using SafeERC20 for IERC20;
/**
* @dev 0. Simply saves an mAsset and then into the vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Units of mAsset to deposit to savings
*/
function saveAndStake(
address _mAsset,
address _save,
address _vault,
uint256 _amount
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
// 1. Get the input mAsset
IERC20(_mAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint imAsset and stake in vault
_saveAndStake(_save, _vault, _amount, true);
}
/**
* @dev 1. Mints an mAsset and then deposits to SAVE
* @param _mAsset mAsset address
* @param _bAsset bAsset address
* @param _save Save address
* @param _vault Boosted Savings Vault address
* @param _amount Amount of bAsset to mint with
* @param _minOut Min amount of mAsset to get back
* @param _stake Add the imAsset to the Boosted Savings Vault?
*/
function saveViaMint(
address _mAsset,
address _save,
address _vault,
address _bAsset,
uint256 _amount,
uint256 _minOut,
bool _stake
) external {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_bAsset != address(0), "Invalid bAsset");
// 1. Get the input bAsset
IERC20(_bAsset).transferFrom(msg.sender, address(this), _amount);
// 2. Mint
uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev 2. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
* optionally staking in the Boosted Savings Vault
* @param _mAsset mAsset address
* @param _save Save address
* @param _vault Boosted vault address
* @param _uniswap Uniswap router address
* @param _amountOutMin Min uniswap output in bAsset units
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
* @param _minOutMStable Min amount of mAsset to receive
* @param _stake Add the imAsset to the Savings Vault?
*/
function saveViaUniswapETH(
address _mAsset,
address _save,
address _vault,
address _uniswap,
uint256 _amountOutMin,
address[] calldata _path,
uint256 _minOutMStable,
bool _stake
) external payable {
require(_mAsset != address(0), "Invalid mAsset");
require(_save != address(0), "Invalid save");
require(_vault != address(0), "Invalid vault");
require(_uniswap != address(0), "Invalid uniswap");
// 1. Get the bAsset
uint256[] memory amounts =
IUniswapV2Router02(_uniswap).swapExactETHForTokens{ value: msg.value }(
_amountOutMin,
_path,
address(this),
block.timestamp + 1000
);
// 2. Purchase mAsset
uint256 massetsMinted =
IMasset(_mAsset).mint(
_path[_path.length - 1],
amounts[amounts.length - 1],
_minOutMStable,
address(this)
);
// 3. Mint imAsset and optionally stake in vault
_saveAndStake(_save, _vault, massetsMinted, _stake);
}
/**
* @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
* @param _mAsset mAsset address
* @param _uniswap Uniswap router address
* @param _ethAmount ETH amount to sell
* @param _path Sell path on Uniswap (e.g. [WETH, DAI])
*/
function estimate_saveViaUniswapETH(
address _mAsset,
address _uniswap,
uint256 _ethAmount,
address[] calldata _path
) external view returns (uint256 out) {
require(_mAsset != address(0), "Invalid mAsset");
require(_uniswap != address(0), "Invalid uniswap");
uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
}
/** @dev Internal func to deposit into Save and optionally stake in the vault
* @param _save Save address
* @param _vault Boosted vault address
* @param _amount Amount of mAsset to deposit
* @param _stake Add the imAsset to the Savings Vault?
*/
function _saveAndStake(
address _save,
address _vault,
uint256 _amount,
bool _stake
) internal {
if (_stake) {
uint256 credits = ISavingsContractV2(_save).depositSavings(_amount, address(this));
IBoostedSavingsVault(_vault).stake(msg.sender, credits);
} else {
ISavingsContractV2(_save).depositSavings(_amount, msg.sender);
}
}
/** @dev Internal func to get estimated Uniswap output from WETH to token trade */
function _getAmountOut(
address _uniswap,
uint256 _amountIn,
address[] memory _path
) internal view returns (uint256) {
uint256[] memory amountsOut = IUniswapV2Router02(_uniswap).getAmountsOut(_amountIn, _path);
return amountsOut[amountsOut.length - 1];
}
/**
* @dev Approve mAsset, Save and multiple bAssets
*/
function approve(
address _mAsset,
address _save,
address _vault,
address[] calldata _bAssets
) external onlyOwner {
_approve(_mAsset, _save);
_approve(_save, _vault);
_approve(_bAssets, _mAsset);
}
/**
* @dev Approve one token/spender
*/
function approve(address _token, address _spender) external onlyOwner {
_approve(_token, _spender);
}
/**
* @dev Approve multiple tokens/one spender
*/
function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
function _approve(address _token, address _spender) internal {
require(_spender != address(0), "Invalid spender");
require(_token != address(0), "Invalid token");
IERC20(_token).safeApprove(_spender, 2**256 - 1);
}
function _approve(address[] calldata _tokens, address _spender) internal {
require(_spender != address(0), "Invalid spender");
for (uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token");
IERC20(_tokens[i]).safeApprove(_spender, 2**256 - 1);
}
}
} | // 3 FLOWS
// 0 - SAVE
// 1 - MINT AND SAVE
// 2 - BUY AND SAVE (ETH via Uni) | LineComment | approve | function approve(address[] calldata _tokens, address _spender) external onlyOwner {
_approve(_tokens, _spender);
}
| /**
* @dev Approve multiple tokens/one spender
*/ | NatSpecMultiLine | v0.8.2+commit.661d1103 | MIT | ipfs://41f8902acf27ffe8ff89ce6a7ba9aa9a5d6e95217982e5456b7a917e0bf3b42a | {
"func_code_index": [
6573,
6706
]
} | 56,669 |
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.s
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | totalSupply | function totalSupply() external view returns (uint256);
| /**
* @dev Returns the amount of tokens in existence.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
94,
154
]
} | 56,670 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.s
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | balanceOf | function balanceOf(address account) external view returns (uint256);
| /**
* @dev Returns the amount of tokens owned by `account`.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
237,
310
]
} | 56,671 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.s
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | transfer | function transfer(address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.s
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
535,
617
]
} | 56,672 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.s
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | allowance | function allowance(address owner, address spender) external view returns (uint256);
| /**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
896,
984
]
} | 56,673 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.s
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | approve | function approve(address spender, uint256 amount) external returns (bool);
| /**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
1650,
1729
]
} | 56,674 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.s
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
2042,
2144
]
} | 56,675 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity functi
* on calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | isContract | function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
| /**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
606,
1230
]
} | 56,676 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity functi
* on calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | sendValue | function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
| /**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
2160,
2562
]
} | 56,677 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity functi
* on calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCall | function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
| /**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity functi
* on calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
3327,
3505
]
} | 56,678 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity functi
* on calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCall | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
| /**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
3730,
3931
]
} | 56,679 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity functi
* on calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCallWithValue | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
| /**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
4301,
4532
]
} | 56,680 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity functi
* on calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCallWithValue | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
| /**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
4783,
5104
]
} | 56,681 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
259,
445
]
} | 56,682 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
723,
864
]
} | 56,683 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | sub | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
1162,
1359
]
} | 56,684 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
1613,
2089
]
} | 56,685 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
2560,
2697
]
} | 56,686 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | div | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
3188,
3471
]
} | 56,687 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
3931,
4066
]
} | 56,688 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mod | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
4546,
4717
]
} | 56,689 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return address(0);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | owner | function owner() public view returns (address) {
return address(0);
}
| /**
* @dev Returns the address of the current owner.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
497,
585
]
} | 56,690 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return address(0);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | renounceOwnership | function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
}
| /**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
1146,
1269
]
} | 56,691 |
||
KAMEHAMEHAToken | KAMEHAMEHAToken.sol | 0xd5a902d62ab8ea3f90101c0326f8b0ed306181a7 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return address(0);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | transferOwnership | function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
| /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/ | NatSpecMultiLine | v0.6.9+commit.3e3065ac | MIT | ipfs://a8562f9643a207bde4c6a267882073f58c36ac4d34bd4326d3750a5fe57168fb | {
"func_code_index": [
1419,
1674
]
} | 56,692 |
||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | _metadataURI | function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
| /**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
3952,
4138
]
} | 56,693 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | quoteFee | function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
| /**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
4605,
4902
]
} | 56,694 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | mintsLeft | function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
| /**
* @return how many mints are left on that style
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
5496,
5672
]
} | 56,695 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | reservedTokens | function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
| /**
* @return how many mints are currently reserved on the allowlist
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
5754,
6011
]
} | 56,696 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | availableForPublicMinting | function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
| /**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
6122,
6365
]
} | 56,697 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | verifyAllowlistEntryProof | function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
| /**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
6584,
7039
]
} | 56,698 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | decreaseAllowance | function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
| /**
* @dev called by Splice to decrement the allowance for requestor
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
7121,
7682
]
} | 56,699 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | addAllowlist | function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
| /**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
8155,
9240
]
} | 56,700 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | isMintable | function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
| /**
* @dev will revert when something prevents minting a splice
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
9317,
10926
]
} | 56,701 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | freeze | function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
| /**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
11283,
11827
]
} | 56,702 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | incrementMintedPerStyle | function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
| /**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
12000,
12455
]
} | 56,703 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | enablePartnership | function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
| /**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
12984,
13407
]
} | 56,704 |
||||
SplicePriceStrategyStatic | contracts/SpliceStyleNFT.sol | 0xee25f9e9f3fe1015e1f695ab50bca299aaf4dcf1 | Solidity | SpliceStyleNFT | contract SpliceStyleNFT is
ERC721EnumerableUpgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeCastUpgradeable for uint256;
error BadReservationParameters(uint32 reservation, uint32 mintsLeft);
error AllowlistDurationTooShort(uint256 diff);
/// @notice you wanted to set an allowlist on a style that already got one
error AllowlistNotOverridable(uint32 styleTokenId);
/// @notice someone wanted to modify the style NFT without owning it.
error NotControllingStyle(uint32 styleTokenId);
/// @notice The style cap has been reached. You can't mint more items using that style
error StyleIsFullyMinted();
/// @notice Sales is not active on the style
error SaleNotActive(uint32 styleTokenId);
/// @notice Reservation limit exceeded
error PersonalReservationLimitExceeded(uint32 styleTokenId);
/// @notice
error NotEnoughTokensToMatchReservation(uint32 styleTokenId);
/// @notice
error StyleIsFrozen();
error OriginNotAllowed(string reason);
error BadMintInput(string reason);
error CantFreezeAnUncompleteCollection(uint32 mintsLeft);
error InvalidCID();
//https://docs.opensea.io/docs/metadata-standards#ipfs-and-arweave-uris
event PermanentURI(string _value, uint256 indexed _id);
event Minted(uint32 indexed styleTokenId, uint32 cap, string metadataCID);
event SharesChanged(uint16 percentage);
event AllowlistInstalled(
uint32 indexed styleTokenId,
uint32 reserved,
uint8 mintsPerAddress,
uint64 until
);
CountersUpgradeable.Counter private _styleTokenIds;
mapping(address => bool) public isStyleMinter;
mapping(uint32 => StyleSettings) styleSettings;
mapping(uint32 => Allowlist) allowlists;
/// @notice how many pieces has an (allowed) address already minted on a style
mapping(uint32 => mapping(address => uint8)) mintsAlreadyAllowed;
/**
* @dev styleTokenId => Partnership
*/
mapping(uint32 => Partnership) private _partnerships;
uint16 public ARTIST_SHARE;
Splice public spliceNFT;
PaymentSplitterController public paymentSplitterController;
function initialize() public initializer {
__ERC721_init('Splice Style NFT', 'SPLYLE');
__ERC721Enumerable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init();
ARTIST_SHARE = 8500;
}
modifier onlyStyleMinter() {
require(isStyleMinter[msg.sender], 'not allowed to mint styles');
_;
}
modifier onlySplice() {
require(msg.sender == address(spliceNFT), 'only callable by Splice');
_;
}
modifier controlsStyle(uint32 styleTokenId) {
if (!isStyleMinter[msg.sender] && msg.sender != ownerOf(styleTokenId)) {
revert NotControllingStyle(styleTokenId);
}
_;
}
function updateArtistShare(uint16 share) public onlyOwner {
require(share <= 10000 && share > 7500, 'we will never take more than 25%');
ARTIST_SHARE = share;
emit SharesChanged(share);
}
function setPaymentSplitter(PaymentSplitterController ps) external onlyOwner {
if (address(paymentSplitterController) != address(0)) {
revert('can only be called once.');
}
paymentSplitterController = ps;
}
function setSplice(Splice _spliceNFT) external onlyOwner {
if (address(spliceNFT) != address(0)) {
revert('can only be called once.');
}
spliceNFT = _spliceNFT;
}
function toggleStyleMinter(address minter, bool newValue) external onlyOwner {
isStyleMinter[minter] = newValue;
}
function getPartnership(uint32 styleTokenId)
public
view
returns (
address[] memory collections,
uint256 until,
bool exclusive
)
{
Partnership memory p = _partnerships[styleTokenId];
return (p.collections, p.until, p.exclusive);
}
/**
* @dev we assume that our metadata CIDs are folder roots containing a /metadata.json. That's how nft.storage does it.
*/
function _metadataURI(string memory metadataCID)
private
pure
returns (string memory)
{
return string(abi.encodePacked('ipfs://', metadataCID, '/metadata.json'));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), 'nonexistent token');
return _metadataURI(styleSettings[uint32(tokenId)].styleCID);
}
/**
* todo if there's more than one mint request in one block the quoted fee might be lower
* than what the artist expects, (when using a bonded price strategy)
* @return fee the fee required to mint splices of that style
*/
function quoteFee(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds
) public view returns (uint256 fee) {
fee = styleSettings[styleTokenId].priceStrategy.quote(
styleTokenId,
originCollections,
originTokenIds
);
}
function getSettings(uint32 styleTokenId)
public
view
returns (StyleSettings memory)
{
return styleSettings[styleTokenId];
}
function isSaleActive(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].salesIsActive;
}
function toggleSaleIsActive(uint32 styleTokenId, bool newValue)
external
controlsStyle(styleTokenId)
{
if (isFrozen(styleTokenId)) {
revert StyleIsFrozen();
}
styleSettings[styleTokenId].salesIsActive = newValue;
}
/**
* @return how many mints are left on that style
*/
function mintsLeft(uint32 styleTokenId) public view returns (uint32) {
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @return how many mints are currently reserved on the allowlist
*/
function reservedTokens(uint32 styleTokenId) public view returns (uint32) {
if (block.timestamp > allowlists[styleTokenId].reservedUntil) {
//reservation period has ended
return 0;
}
return allowlists[styleTokenId].numReserved;
}
/**
* @return how many splices can be minted except those reserved on an allowlist for that style
*/
function availableForPublicMinting(uint32 styleTokenId)
public
view
returns (uint32)
{
return
styleSettings[styleTokenId].cap -
styleSettings[styleTokenId].mintedOfStyle -
reservedTokens(styleTokenId);
}
/**
* @param allowlistProof a list of leaves in the merkle tree that are needed to perform the proof
* @param requestor the subject account of the proof
* @return whether the proof could be verified
*/
function verifyAllowlistEntryProof(
uint32 styleTokenId,
bytes32[] memory allowlistProof,
address requestor
) external view returns (bool) {
return
MerkleProofUpgradeable.verify(
allowlistProof,
allowlists[styleTokenId].merkleRoot,
//or maybe: https://ethereum.stackexchange.com/questions/884/how-to-convert-an-address-to-bytes-in-solidity/41356
keccak256(abi.encodePacked(requestor))
);
}
/**
* @dev called by Splice to decrement the allowance for requestor
*/
function decreaseAllowance(uint32 styleTokenId, address requestor)
external
nonReentrant
onlySplice
{
// CHECKS
if (
mintsAlreadyAllowed[styleTokenId][requestor] + 1 >
allowlists[styleTokenId].mintsPerAddress
) {
revert PersonalReservationLimitExceeded(styleTokenId);
}
if (allowlists[styleTokenId].numReserved < 1) {
revert NotEnoughTokensToMatchReservation(styleTokenId);
}
// EFFECTS
allowlists[styleTokenId].numReserved -= 1;
mintsAlreadyAllowed[styleTokenId][requestor] += 1;
}
/**
* @notice an allowlist gives privilege to a dedicated list of users to mint this style by presenting a merkle proof
@param styleTokenId the style token id
* @param numReserved_ how many reservations shall be made
* @param mintsPerAddress_ how many mints are allowed per one distinct address
* @param merkleRoot_ the merkle root of a tree of allowed addresses
* @param reservedUntil_ a timestamp until when the allowlist shall be in effect
*/
function addAllowlist(
uint32 styleTokenId,
uint32 numReserved_,
uint8 mintsPerAddress_,
bytes32 merkleRoot_,
uint64 reservedUntil_
) external controlsStyle(styleTokenId) {
//CHECKS
if (allowlists[styleTokenId].reservedUntil != 0) {
revert AllowlistNotOverridable(styleTokenId);
}
uint32 stillAvailable = mintsLeft(styleTokenId);
if (
numReserved_ > stillAvailable || mintsPerAddress_ > stillAvailable //that 2nd edge case is actually not important (minting would fail anyway when cap is exceeded)
) {
revert BadReservationParameters(numReserved_, stillAvailable);
}
if (reservedUntil_ < block.timestamp + 1 days) {
revert AllowlistDurationTooShort(reservedUntil_);
}
//EFFECTS
allowlists[styleTokenId] = Allowlist({
numReserved: numReserved_,
merkleRoot: merkleRoot_,
reservedUntil: reservedUntil_,
mintsPerAddress: mintsPerAddress_
});
emit AllowlistInstalled(
styleTokenId,
numReserved_,
mintsPerAddress_,
reservedUntil_
);
}
/**
* @dev will revert when something prevents minting a splice
*/
function isMintable(
uint32 styleTokenId,
IERC721[] memory originCollections,
uint256[] memory originTokenIds,
address minter
) public view returns (bool) {
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (
originCollections.length == 0 ||
originTokenIds.length == 0 ||
originCollections.length != originTokenIds.length
) {
revert BadMintInput('inconsistent input lengths');
}
if (styleSettings[styleTokenId].maxInputs < originCollections.length) {
revert OriginNotAllowed('too many inputs');
}
Partnership memory partnership = _partnerships[styleTokenId];
bool partnershipIsActive = (partnership.collections.length > 0 &&
partnership.until > block.timestamp);
uint8 partner_count = 0;
for (uint256 i = 0; i < originCollections.length; i++) {
if (i > 0) {
if (
address(originCollections[i]) <= address(originCollections[i - 1])
) {
revert BadMintInput('duplicate or unordered origin input');
}
}
if (partnershipIsActive) {
if (
ArrayLib.contains(
partnership.collections,
address(originCollections[i])
)
) {
partner_count++;
}
}
}
if (partnershipIsActive) {
//this saves a very slight amount of gas compared to &&
if (partnership.exclusive) {
if (partner_count != originCollections.length) {
revert OriginNotAllowed('exclusive partnership');
}
}
}
return true;
}
function isFrozen(uint32 styleTokenId) public view returns (bool) {
return styleSettings[styleTokenId].isFrozen;
}
/**
* @notice freezing a fully minted style means to disable its sale and set its splice's baseUrl to a fixed IPFS CID. That IPFS directory must contain all metadata for the splices.
* @param cid an IPFS content hash
*/
function freeze(uint32 styleTokenId, string memory cid)
public
onlyStyleMinter
{
if (bytes(cid).length < 46) {
revert InvalidCID();
}
//@todo: this might be unnecessarily strict
if (mintsLeft(styleTokenId) != 0) {
revert CantFreezeAnUncompleteCollection(mintsLeft(styleTokenId));
}
styleSettings[styleTokenId].salesIsActive = false;
styleSettings[styleTokenId].styleCID = cid;
styleSettings[styleTokenId].isFrozen = true;
emit PermanentURI(tokenURI(styleTokenId), styleTokenId);
}
/**
* @dev only called by Splice. Increments the amount of minted splices.
* @return the new highest amount. Used as incremental part of the splice token id
*/
function incrementMintedPerStyle(uint32 styleTokenId)
public
onlySplice
returns (uint32)
{
if (!isSaleActive(styleTokenId)) {
revert SaleNotActive(styleTokenId);
}
if (mintsLeft(styleTokenId) == 0) {
revert StyleIsFullyMinted();
}
styleSettings[styleTokenId].mintedOfStyle += 1;
styleSettings[styleTokenId].priceStrategy.onMinted(styleTokenId);
return styleSettings[styleTokenId].mintedOfStyle;
}
/**
* @notice collection partnerships have an effect on minting availability. They restrict styles to be minted only on certain collections. Partner collections receive a share of the platform fee.
* @param until after this timestamp the partnership is not in effect anymore. Set to a very high value to add a collection constraint to a style.
* @param exclusive a non-exclusive partnership allows other origins to mint. When trying to mint on an exclusive partnership with an unsupported input, it will fail.
*/
function enablePartnership(
address[] memory collections,
uint32 styleTokenId,
uint64 until,
bool exclusive
) external onlyStyleMinter {
require(
styleSettings[styleTokenId].mintedOfStyle == 0,
'cant add a partnership after minting started'
);
_partnerships[styleTokenId] = Partnership({
collections: collections,
until: until,
exclusive: exclusive
});
}
function setupPaymentSplitter(
uint256 styleTokenId,
address artist,
address partner
) internal returns (address ps) {
address[] memory members;
uint256[] memory shares;
if (partner != address(0)) {
members = new address[](3);
shares = new uint256[](3);
uint256 splitShare = (10_000 - ARTIST_SHARE) / 2;
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = splitShare;
members[2] = partner;
shares[2] = splitShare;
} else {
members = new address[](2);
shares = new uint256[](2);
members[0] = artist;
shares[0] = ARTIST_SHARE;
members[1] = spliceNFT.platformBeneficiary();
shares[1] = 10_000 - ARTIST_SHARE;
}
ps = paymentSplitterController.createSplit(styleTokenId, members, shares);
}
/**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/
function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from != address(0) && to != address(0)) {
//its not a mint or a burn but a real transfer
paymentSplitterController.replaceShareholder(tokenId, payable(from), to);
}
}
} | mint | function mint(
uint32 cap_,
string memory metadataCID_,
ISplicePriceStrategy priceStrategy_,
bool salesIsActive_,
uint8 maxInputs_,
address artist_,
address partnershipBeneficiary_
) external onlyStyleMinter returns (uint32 styleTokenId) {
//CHECKS
if (bytes(metadataCID_).length < 46) {
revert InvalidCID();
}
if (artist_ == address(0)) {
artist_ = msg.sender;
}
//EFFECTS
_styleTokenIds.increment();
styleTokenId = _styleTokenIds.current().toUint32();
styleSettings[styleTokenId] = StyleSettings({
mintedOfStyle: 0,
cap: cap_,
priceStrategy: priceStrategy_,
salesIsActive: salesIsActive_,
isFrozen: false,
styleCID: metadataCID_,
maxInputs: maxInputs_,
paymentSplitter: setupPaymentSplitter(
styleTokenId,
artist_,
partnershipBeneficiary_
)
});
//INTERACTIONS
_safeMint(artist_, styleTokenId);
emit Minted(styleTokenId, cap_, metadataCID_);
}
| /**
* @notice creates a new style NFT
* @param cap_ how many splices can be minted of this style
* @param metadataCID_ an IPFS CID pointing to the style metadata. Must be a directory, containing a metadata.json file.
* @param priceStrategy_ address of an ISplicePriceStrategy instance that's configured to return fee quotes for the new style (e.g. static)
* @param salesIsActive_ splices of this style can be minted once this method is finished (careful: some other methods will only run when no splices have ever been minted)
* @param maxInputs_ how many origin inputs are allowed for a mint (e.g. 2 NFT collections)
* @param artist_ the first owner of that style. If 0 the minter is the first owner.
* @param partnershipBeneficiary_ an address that gets 50% of platform shares. Can be 0
*/ | NatSpecMultiLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
15104,
16127
]
} | 56,705 |
||||
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() external view returns (uint256);
| /**
* @dev Returns the amount of tokens in existence.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
94,
154
]
} | 56,706 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address account) external view returns (uint256);
| /**
* @dev Returns the amount of tokens owned by `account`.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
237,
310
]
} | 56,707 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | transfer | function transfer(address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
534,
616
]
} | 56,708 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | allowance | function allowance(address owner, address spender) external view returns (uint256);
| /**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
895,
983
]
} | 56,709 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | approve | function approve(address spender, uint256 amount) external returns (bool);
| /**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
1647,
1726
]
} | 56,710 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
2039,
2141
]
} | 56,711 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
259,
445
]
} | 56,712 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
723,
864
]
} | 56,713 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
1162,
1359
]
} | 56,714 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
1613,
2089
]
} | 56,715 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
2560,
2697
]
} | 56,716 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
3188,
3471
]
} | 56,717 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
3931,
4066
]
} | 56,718 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
4546,
4717
]
} | 56,719 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | isContract | function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
| /**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
606,
1230
]
} | 56,720 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | sendValue | function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
| /**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
2160,
2562
]
} | 56,721 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | functionCall | function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
| /**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
3318,
3496
]
} | 56,722 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | functionCall | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
| /**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
3721,
3922
]
} | 56,723 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | functionCallWithValue | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
| /**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
4292,
4523
]
} | 56,724 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | functionCallWithValue | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
| /**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
4774,
5095
]
} | 56,725 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | owner | function owner() public view returns (address) {
return _owner;
}
| /**
* @dev Returns the address of the current owner.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
488,
572
]
} | 56,726 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | renounceOwnership | function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
| /**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
1130,
1283
]
} | 56,727 |
Trendy | Trendy.sol | 0x99ee2e4c0441edd908ff59b0468644d3b754a97d | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
| /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | None | ipfs://c15aa1b2ca56c13d2143ee200ac4b3b81c7eca07c2a9c5eef9f6cbaeae3c94c7 | {
"func_code_index": [
1433,
1682
]
} | 56,728 |
Jinsamo | Jinsamo.sol | 0xe072658111387bd922c4ac41dbe4dd6bf7d26ffb | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0);
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
| /**
* @dev Multiplies two numbers, reverts on overflow.
*/ | NatSpecMultiLine | v0.4.26+commit.4563c3fc | None | bzzr://42a1898faa2d98bad89fbc1d64deb8d8d0a43b1951e4c32659ba591b27a6d65e | {
"func_code_index": [
90,
278
]
} | 56,729 |
Jinsamo | Jinsamo.sol | 0xe072658111387bd922c4ac41dbe4dd6bf7d26ffb | Solidity | TokenERC20 | contract TokenERC20 is owned{
using SafeMath for uint256;
// Public variables of the token
string public name = "Jinsamo";
string public symbol = 'JSM';
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply = 1000000000000000000000000000000;
bool public released = true;
// 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 generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = 0; // Give the creator all initial tokens
name = "Jinsamo"; // Set the name for display purposes
symbol = "JSM"; // Set the symbol for display purposes
}
function release() public onlyOwner{
require (owner == msg.sender);
released = !released;
}
modifier onlyReleased() {
require(released);
_;
}
function _transfer(address _from, address _to, uint _value) internal onlyReleased {
// 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].add(balanceOf[_to]);
// Subtract from the sender
balanceOf[_from] = balanceOf[_from].sub(_value);
// Add the same to the recipient
balanceOf[_to] = balanceOf[_to].add(_value);
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from].add(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 onlyReleased returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in 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 onlyReleased returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public onlyReleased
returns (bool success) {
require(_spender != address(0));
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public onlyReleased
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 onlyReleased returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender
totalSupply = totalSupply.sub(_value); // Updates totalSupply
emit 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 onlyReleased returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance
totalSupply = totalSupply.sub(_value); // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | transfer | function transfer(address _to, uint256 _value) public onlyReleased returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
| /**
* 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.26+commit.4563c3fc | None | bzzr://42a1898faa2d98bad89fbc1d64deb8d8d0a43b1951e4c32659ba591b27a6d65e | {
"func_code_index": [
2836,
3006
]
} | 56,730 |
||
Jinsamo | Jinsamo.sol | 0xe072658111387bd922c4ac41dbe4dd6bf7d26ffb | Solidity | TokenERC20 | contract TokenERC20 is owned{
using SafeMath for uint256;
// Public variables of the token
string public name = "Jinsamo";
string public symbol = 'JSM';
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply = 1000000000000000000000000000000;
bool public released = true;
// 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 generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = 0; // Give the creator all initial tokens
name = "Jinsamo"; // Set the name for display purposes
symbol = "JSM"; // Set the symbol for display purposes
}
function release() public onlyOwner{
require (owner == msg.sender);
released = !released;
}
modifier onlyReleased() {
require(released);
_;
}
function _transfer(address _from, address _to, uint _value) internal onlyReleased {
// 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].add(balanceOf[_to]);
// Subtract from the sender
balanceOf[_from] = balanceOf[_from].sub(_value);
// Add the same to the recipient
balanceOf[_to] = balanceOf[_to].add(_value);
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from].add(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 onlyReleased returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in 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 onlyReleased returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public onlyReleased
returns (bool success) {
require(_spender != address(0));
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public onlyReleased
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 onlyReleased returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender
totalSupply = totalSupply.sub(_value); // Updates totalSupply
emit 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 onlyReleased returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance
totalSupply = totalSupply.sub(_value); // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public onlyReleased returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
_transfer(_from, _to, _value);
return true;
}
| /**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in 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.26+commit.4563c3fc | None | bzzr://42a1898faa2d98bad89fbc1d64deb8d8d0a43b1951e4c32659ba591b27a6d65e | {
"func_code_index": [
3281,
3630
]
} | 56,731 |
||
Jinsamo | Jinsamo.sol | 0xe072658111387bd922c4ac41dbe4dd6bf7d26ffb | Solidity | TokenERC20 | contract TokenERC20 is owned{
using SafeMath for uint256;
// Public variables of the token
string public name = "Jinsamo";
string public symbol = 'JSM';
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply = 1000000000000000000000000000000;
bool public released = true;
// 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 generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = 0; // Give the creator all initial tokens
name = "Jinsamo"; // Set the name for display purposes
symbol = "JSM"; // Set the symbol for display purposes
}
function release() public onlyOwner{
require (owner == msg.sender);
released = !released;
}
modifier onlyReleased() {
require(released);
_;
}
function _transfer(address _from, address _to, uint _value) internal onlyReleased {
// 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].add(balanceOf[_to]);
// Subtract from the sender
balanceOf[_from] = balanceOf[_from].sub(_value);
// Add the same to the recipient
balanceOf[_to] = balanceOf[_to].add(_value);
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from].add(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 onlyReleased returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in 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 onlyReleased returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public onlyReleased
returns (bool success) {
require(_spender != address(0));
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public onlyReleased
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 onlyReleased returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender
totalSupply = totalSupply.sub(_value); // Updates totalSupply
emit 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 onlyReleased returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance
totalSupply = totalSupply.sub(_value); // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | approve | function approve(address _spender, uint256 _value) public onlyReleased
returns (bool success) {
require(_spender != address(0));
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
| /**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/ | NatSpecMultiLine | v0.4.26+commit.4563c3fc | None | bzzr://42a1898faa2d98bad89fbc1d64deb8d8d0a43b1951e4c32659ba591b27a6d65e | {
"func_code_index": [
3894,
4181
]
} | 56,732 |
||
Jinsamo | Jinsamo.sol | 0xe072658111387bd922c4ac41dbe4dd6bf7d26ffb | Solidity | TokenERC20 | contract TokenERC20 is owned{
using SafeMath for uint256;
// Public variables of the token
string public name = "Jinsamo";
string public symbol = 'JSM';
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply = 1000000000000000000000000000000;
bool public released = true;
// 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 generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = 0; // Give the creator all initial tokens
name = "Jinsamo"; // Set the name for display purposes
symbol = "JSM"; // Set the symbol for display purposes
}
function release() public onlyOwner{
require (owner == msg.sender);
released = !released;
}
modifier onlyReleased() {
require(released);
_;
}
function _transfer(address _from, address _to, uint _value) internal onlyReleased {
// 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].add(balanceOf[_to]);
// Subtract from the sender
balanceOf[_from] = balanceOf[_from].sub(_value);
// Add the same to the recipient
balanceOf[_to] = balanceOf[_to].add(_value);
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from].add(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 onlyReleased returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in 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 onlyReleased returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public onlyReleased
returns (bool success) {
require(_spender != address(0));
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public onlyReleased
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 onlyReleased returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender
totalSupply = totalSupply.sub(_value); // Updates totalSupply
emit 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 onlyReleased returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance
totalSupply = totalSupply.sub(_value); // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | burn | function burn(uint256 _value) public onlyReleased returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender
totalSupply = totalSupply.sub(_value); // Updates totalSupply
emit 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.26+commit.4563c3fc | None | bzzr://42a1898faa2d98bad89fbc1d64deb8d8d0a43b1951e4c32659ba591b27a6d65e | {
"func_code_index": [
4723,
5157
]
} | 56,733 |
||
Jinsamo | Jinsamo.sol | 0xe072658111387bd922c4ac41dbe4dd6bf7d26ffb | Solidity | TokenERC20 | contract TokenERC20 is owned{
using SafeMath for uint256;
// Public variables of the token
string public name = "Jinsamo";
string public symbol = 'JSM';
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply = 1000000000000000000000000000000;
bool public released = true;
// 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 generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = 0; // Give the creator all initial tokens
name = "Jinsamo"; // Set the name for display purposes
symbol = "JSM"; // Set the symbol for display purposes
}
function release() public onlyOwner{
require (owner == msg.sender);
released = !released;
}
modifier onlyReleased() {
require(released);
_;
}
function _transfer(address _from, address _to, uint _value) internal onlyReleased {
// 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].add(balanceOf[_to]);
// Subtract from the sender
balanceOf[_from] = balanceOf[_from].sub(_value);
// Add the same to the recipient
balanceOf[_to] = balanceOf[_to].add(_value);
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from].add(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 onlyReleased returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in 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 onlyReleased returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public onlyReleased
returns (bool success) {
require(_spender != address(0));
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public onlyReleased
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 onlyReleased returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender
totalSupply = totalSupply.sub(_value); // Updates totalSupply
emit 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 onlyReleased returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance
totalSupply = totalSupply.sub(_value); // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | burnFrom | function burnFrom(address _from, uint256 _value) public onlyReleased returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance
totalSupply = totalSupply.sub(_value); // Update totalSupply
emit 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.26+commit.4563c3fc | None | bzzr://42a1898faa2d98bad89fbc1d64deb8d8d0a43b1951e4c32659ba591b27a6d65e | {
"func_code_index": [
5415,
6114
]
} | 56,734 |
||
Jinsamo | Jinsamo.sol | 0xe072658111387bd922c4ac41dbe4dd6bf7d26ffb | Solidity | Jinsamo | contract Jinsamo is owned, TokenERC20 {
mapping (address => bool) public frozenAccount;
/* This generates a public event on the blockchain that will notify clients */
event FrozenFunds(address target, bool frozen);
/* Initializes contract with initial supply tokens to the creator of the contract */
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) TokenERC20(initialSupply, tokenName, tokenSymbol) public {
}
/* Internal transfer, only can be called by this contract */
function _transfer(address _from, address _to, uint _value) internal onlyReleased {
require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
require (balanceOf[_from] >= _value); // Check if the sender has enough
require (balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
require(!frozenAccount[_from]); // Check if sender is frozen
require(!frozenAccount[_to]); // Check if recipient is frozen
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender
balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient
emit Transfer(_from, _to, _value);
}
/// @notice Create `mintedAmount` tokens and send it to `target`
/// @param target Address to receive the tokens
/// @param mintedAmount the amount of tokens it will receive
/// mintedAmount 1000000000000000000 = 1.000000000000000000
function mintToken(address target, uint256 mintedAmount) onlyOwner public {
require (mintedAmount > 0);
totalSupply = totalSupply.add(mintedAmount);
balanceOf[target] = balanceOf[target].add(mintedAmount);
emit Transfer(0, this, mintedAmount);
emit Transfer(this, target, mintedAmount);
}
/// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
/// @param target Address to be frozen
/// @param freeze either to freeze it or not
function freezeAccount(address target, bool freeze) onlyOwner public {
frozenAccount[target] = freeze;
emit FrozenFunds(target, freeze);
}
} | _transfer | function _transfer(address _from, address _to, uint _value) internal onlyReleased {
require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
require (balanceOf[_from] >= _value); // Check if the sender has enough
require (balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
require(!frozenAccount[_from]); // Check if sender is frozen
require(!frozenAccount[_to]); // Check if recipient is frozen
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender
balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient
emit Transfer(_from, _to, _value);
| /* Internal transfer, only can be called by this contract */ | Comment | v0.4.26+commit.4563c3fc | None | bzzr://42a1898faa2d98bad89fbc1d64deb8d8d0a43b1951e4c32659ba591b27a6d65e | {
"func_code_index": [
575,
1418
]
} | 56,735 |
||
Jinsamo | Jinsamo.sol | 0xe072658111387bd922c4ac41dbe4dd6bf7d26ffb | Solidity | Jinsamo | contract Jinsamo is owned, TokenERC20 {
mapping (address => bool) public frozenAccount;
/* This generates a public event on the blockchain that will notify clients */
event FrozenFunds(address target, bool frozen);
/* Initializes contract with initial supply tokens to the creator of the contract */
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) TokenERC20(initialSupply, tokenName, tokenSymbol) public {
}
/* Internal transfer, only can be called by this contract */
function _transfer(address _from, address _to, uint _value) internal onlyReleased {
require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
require (balanceOf[_from] >= _value); // Check if the sender has enough
require (balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
require(!frozenAccount[_from]); // Check if sender is frozen
require(!frozenAccount[_to]); // Check if recipient is frozen
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender
balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient
emit Transfer(_from, _to, _value);
}
/// @notice Create `mintedAmount` tokens and send it to `target`
/// @param target Address to receive the tokens
/// @param mintedAmount the amount of tokens it will receive
/// mintedAmount 1000000000000000000 = 1.000000000000000000
function mintToken(address target, uint256 mintedAmount) onlyOwner public {
require (mintedAmount > 0);
totalSupply = totalSupply.add(mintedAmount);
balanceOf[target] = balanceOf[target].add(mintedAmount);
emit Transfer(0, this, mintedAmount);
emit Transfer(this, target, mintedAmount);
}
/// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
/// @param target Address to be frozen
/// @param freeze either to freeze it or not
function freezeAccount(address target, bool freeze) onlyOwner public {
frozenAccount[target] = freeze;
emit FrozenFunds(target, freeze);
}
} | mintToken | function mintToken(address target, uint256 mintedAmount) onlyOwner public {
require (mintedAmount > 0);
totalSupply = totalSupply.add(mintedAmount);
balanceOf[target] = balanceOf[target].add(mintedAmount);
emit Transfer(0, this, mintedAmount);
emit Transfer(this, target, mintedAmount);
}
| /// @notice Create `mintedAmount` tokens and send it to `target`
/// @param target Address to receive the tokens
/// @param mintedAmount the amount of tokens it will receive
/// mintedAmount 1000000000000000000 = 1.000000000000000000 | NatSpecSingleLine | v0.4.26+commit.4563c3fc | None | bzzr://42a1898faa2d98bad89fbc1d64deb8d8d0a43b1951e4c32659ba591b27a6d65e | {
"func_code_index": [
1675,
2018
]
} | 56,736 |
||
Jinsamo | Jinsamo.sol | 0xe072658111387bd922c4ac41dbe4dd6bf7d26ffb | Solidity | Jinsamo | contract Jinsamo is owned, TokenERC20 {
mapping (address => bool) public frozenAccount;
/* This generates a public event on the blockchain that will notify clients */
event FrozenFunds(address target, bool frozen);
/* Initializes contract with initial supply tokens to the creator of the contract */
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) TokenERC20(initialSupply, tokenName, tokenSymbol) public {
}
/* Internal transfer, only can be called by this contract */
function _transfer(address _from, address _to, uint _value) internal onlyReleased {
require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
require (balanceOf[_from] >= _value); // Check if the sender has enough
require (balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
require(!frozenAccount[_from]); // Check if sender is frozen
require(!frozenAccount[_to]); // Check if recipient is frozen
balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender
balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient
emit Transfer(_from, _to, _value);
}
/// @notice Create `mintedAmount` tokens and send it to `target`
/// @param target Address to receive the tokens
/// @param mintedAmount the amount of tokens it will receive
/// mintedAmount 1000000000000000000 = 1.000000000000000000
function mintToken(address target, uint256 mintedAmount) onlyOwner public {
require (mintedAmount > 0);
totalSupply = totalSupply.add(mintedAmount);
balanceOf[target] = balanceOf[target].add(mintedAmount);
emit Transfer(0, this, mintedAmount);
emit Transfer(this, target, mintedAmount);
}
/// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
/// @param target Address to be frozen
/// @param freeze either to freeze it or not
function freezeAccount(address target, bool freeze) onlyOwner public {
frozenAccount[target] = freeze;
emit FrozenFunds(target, freeze);
}
} | freezeAccount | function freezeAccount(address target, bool freeze) onlyOwner public {
frozenAccount[target] = freeze;
emit FrozenFunds(target, freeze);
}
| /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
/// @param target Address to be frozen
/// @param freeze either to freeze it or not | NatSpecSingleLine | v0.4.26+commit.4563c3fc | None | bzzr://42a1898faa2d98bad89fbc1d64deb8d8d0a43b1951e4c32659ba591b27a6d65e | {
"func_code_index": [
2199,
2365
]
} | 56,737 |
||
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SignedSafeMath | library SignedSafeMath {
/**
* @dev Returns the multiplication of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(int256 a, int256 b) internal pure returns (int256) {
return a * b;
}
/**
* @dev Returns the integer division of two signed integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(int256 a, int256 b) internal pure returns (int256) {
return a / b;
}
/**
* @dev Returns the subtraction of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
return a - b;
}
/**
* @dev Returns the addition of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(int256 a, int256 b) internal pure returns (int256) {
return a + b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SignedSafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | mul | function mul(int256 a, int256 b) internal pure returns (int256) {
return a * b;
}
| /**
* @dev Returns the multiplication of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
275,
375
]
} | 56,738 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SignedSafeMath | library SignedSafeMath {
/**
* @dev Returns the multiplication of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(int256 a, int256 b) internal pure returns (int256) {
return a * b;
}
/**
* @dev Returns the integer division of two signed integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(int256 a, int256 b) internal pure returns (int256) {
return a / b;
}
/**
* @dev Returns the subtraction of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
return a - b;
}
/**
* @dev Returns the addition of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(int256 a, int256 b) internal pure returns (int256) {
return a + b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SignedSafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | div | function div(int256 a, int256 b) internal pure returns (int256) {
return a / b;
}
| /**
* @dev Returns the integer division of two signed integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
667,
767
]
} | 56,739 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SignedSafeMath | library SignedSafeMath {
/**
* @dev Returns the multiplication of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(int256 a, int256 b) internal pure returns (int256) {
return a * b;
}
/**
* @dev Returns the integer division of two signed integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(int256 a, int256 b) internal pure returns (int256) {
return a / b;
}
/**
* @dev Returns the subtraction of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
return a - b;
}
/**
* @dev Returns the addition of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(int256 a, int256 b) internal pure returns (int256) {
return a + b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SignedSafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | sub | function sub(int256 a, int256 b) internal pure returns (int256) {
return a - b;
}
| /**
* @dev Returns the subtraction of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
1013,
1113
]
} | 56,740 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SignedSafeMath | library SignedSafeMath {
/**
* @dev Returns the multiplication of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(int256 a, int256 b) internal pure returns (int256) {
return a * b;
}
/**
* @dev Returns the integer division of two signed integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(int256 a, int256 b) internal pure returns (int256) {
return a / b;
}
/**
* @dev Returns the subtraction of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
return a - b;
}
/**
* @dev Returns the addition of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(int256 a, int256 b) internal pure returns (int256) {
return a + b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SignedSafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | add | function add(int256 a, int256 b) internal pure returns (int256) {
return a + b;
}
| /**
* @dev Returns the addition of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
1353,
1453
]
} | 56,741 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | tryAdd | function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
| /**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
161,
388
]
} | 56,742 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | trySub | function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
| /**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
536,
735
]
} | 56,743 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | tryMul | function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
| /**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
885,
1393
]
} | 56,744 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | tryDiv | function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
| /**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
1544,
1744
]
} | 56,745 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | tryMod | function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
| /**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
1905,
2105
]
} | 56,746 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
2347,
2450
]
} | 56,747 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
2728,
2831
]
} | 56,748 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
3085,
3188
]
} | 56,749 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
| /**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
3484,
3587
]
} | 56,750 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
4049,
4152
]
} | 56,751 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | sub | function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
4626,
4871
]
} | 56,752 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | div | function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
| /**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
5364,
5608
]
} | 56,753 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | mod | function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
6266,
6510
]
} | 56,754 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeCast | library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
} | /**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/ | NatSpecMultiLine | toUint224 | function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
| /**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
315,
515
]
} | 56,755 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeCast | library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
} | /**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/ | NatSpecMultiLine | toUint128 | function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
| /**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
813,
1013
]
} | 56,756 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeCast | library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
} | /**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/ | NatSpecMultiLine | toUint96 | function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
| /**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
1307,
1502
]
} | 56,757 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeCast | library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
} | /**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/ | NatSpecMultiLine | toUint64 | function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
| /**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
1796,
1991
]
} | 56,758 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeCast | library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
} | /**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/ | NatSpecMultiLine | toUint32 | function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
| /**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
2285,
2480
]
} | 56,759 |
ShibMars | ShibMars.sol | 0x6c267d4a8a8158cd6b0e4edd010b1e4d1dc04f61 | Solidity | SafeCast | library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
} | /**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/ | NatSpecMultiLine | toUint16 | function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
| /**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://378a96fc78dda756648d48142e08c63a092f8d3c7acea297a126e650f9a6ce48 | {
"func_code_index": [
2774,
2969
]
} | 56,760 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.