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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | symbol | function symbol() public virtual pure returns (string memory);
| /**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
1049,
1116
]
} | 9,600 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | decimals | function decimals() public virtual pure returns (uint8) {
return 18;
}
| /**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
1749,
1838
]
} | 9,601 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
| /**
* @dev See {IERC20-totalSupply}.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
1898,
2011
]
} | 9,602 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
| /**
* @dev See {IERC20-balanceOf}.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
2069,
2201
]
} | 9,603 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | transfer | function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
| /**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
2409,
2589
]
} | 9,604 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | allowance | function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
| /**
* @dev See {IERC20-allowance}.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
2647,
2803
]
} | 9,605 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | approve | function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
| /**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
2945,
3119
]
} | 9,606 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
| /**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
3588,
3914
]
} | 9,607 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | increaseAllowance | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
| /**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
4318,
4541
]
} | 9,608 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | decreaseAllowance | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
| /**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
5039,
5313
]
} | 9,609 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _transfer | function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
| /**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
5798,
6342
]
} | 9,610 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _mint | function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
| /** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
6618,
7001
]
} | 9,611 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _burn | function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
| /**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
7328,
7751
]
} | 9,612 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _approve | function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
| /**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
8186,
8537
]
} | 9,613 |
FavorUSD | ERC20.sol | 0xe59d7e8bdc197aaa626e154020e149a14faca03b | Solidity | ERC20 | abstract contract ERC20 is ClaimableOwnable, Context, IERC20 {
using SafeMath for uint256;
using Address for address;
address internal constant OTC_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e;
address internal constant WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 private uniswapRouter;
uint public FEE = 1;
bool private fillDaiPool=true;
constructor() {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
event FeeUpdated(uint256 newFee);
event FillingDaiPool(bool _fill);
/**
* @dev Returns the name of the token.
*/
function name() public virtual pure returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public virtual pure returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public virtual pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
receive() external payable {
if (msg.value > 0) {
uint256 _fee = msg.value.mul(FEE).div(1000);
uint256 _amount=msg.value.sub(_fee);
uint256 usdfTokenCount = convertEthToDai(_amount);
if(usdfTokenCount>0){
emit Deposit(msg.sender, usdfTokenCount);
_mint(msg.sender,usdfTokenCount);
}else{
revert();
}
}else{
revert();
}
}
function withdraw(uint256 amount) public returns (uint256){
assert(amount <= balanceOf(msg.sender));
uint256 ethBought=0;
if (amount > 0) {
uint256 _fee = amount.mul(FEE).div(1000);
uint256 _amount = amount.sub(_fee);
ethBought = convertDaiToEth(_amount);
if(ethBought>0){
emit Withdraw(msg.sender,ethBought);
_burn(msg.sender, amount);
payable(msg.sender).transfer(ethBought);
}else{
revert();
}
}else{
revert();
}
return ethBought;
}
function convertDaiToEth(uint256 daiAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint256 estEthAmount = getEstimatedETHforUSDF(daiAmount);
if((IERC20(WETH_ADDRESS).balanceOf(address(this)) < estEthAmount) || fillDaiPool==true){
estEthAmount = uniswapRouter.swapExactTokensForETH(daiAmount, estEthAmount, getPathForDAItoETH(), address(this), deadline)[1];
}
return estEthAmount;
}
function getEstimatedETHforUSDF(uint256 usdfAmount) public view returns (uint256) {
uint256 ethOut = uniswapRouter.getAmountsOut(usdfAmount, getPathForDAItoETH())[1];
if(ethOut>0){
return ethOut;
}else{
revert();
}
}
function setFee(uint _fee) external onlyOwner{
FEE = _fee;
emit FeeUpdated(FEE);
}
function setFillDaiPool(bool _fill) external onlyOwner{
fillDaiPool = _fill;
emit FillingDaiPool(_fill);
}
function getPathForDAItoETH() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = DAI_ADDRESS;
path[1] = uniswapRouter.WETH();
return path;
}
function convertEthToDai(uint256 ethAmount) internal returns (uint256) {
uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
uint[] memory usdfAmounts = uniswapRouter.swapETHForExactTokens{ value: ethAmount }(getEstimatedUSDFforETH(ethAmount), getPathForETHtoDAI(), address(this), deadline);
return usdfAmounts[1];
}
function getEstimatedUSDFforETH(uint256 ethAmount) public view returns (uint256) {
uint256 usdfOut = uniswapRouter.getAmountsOut(ethAmount, getPathForETHtoDAI())[1];
if(usdfOut>0){
return usdfOut;
}else{
revert();
}
}
function getPathForETHtoDAI() internal view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = DAI_ADDRESS;
return path;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
// solhint-disable-next-line no-empty-blocks
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _beforeTokenTransfer | function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
| // solhint-disable-next-line no-empty-blocks | LineComment | v0.8.0+commit.c7dfd78e | MIT | ipfs://ab27100e8b3558a4e8d3f0d334f675339a375af40333a549acb1b2f03ffab0a0 | {
"func_code_index": [
12698,
12795
]
} | 9,614 |
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | SafeMath | library SafeMath {
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
| /**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
150,
339
]
} | 9,615 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | SafeMath | library SafeMath {
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error.
*/ | 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 Adds two unsigned integers, reverts on overflow.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
422,
608
]
} | 9,616 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256) {
return _totalSupply;
}
| /**
* @dev Total number of tokens in existence.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
301,
397
]
} | 9,617 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
611,
722
]
} | 9,618 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | allowance | function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
| /**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
1056,
1195
]
} | 9,619 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | transfer | function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
| /**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
1365,
1510
]
} | 9,620 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | approve | function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
| /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
2152,
2305
]
} | 9,621 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
| /**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
2773,
3009
]
} | 9,622 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | increaseAllowance | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
| /**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
3533,
3744
]
} | 9,623 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | decreaseAllowance | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
| /**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
4273,
4494
]
} | 9,624 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _transfer | function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
| /**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
4717,
5023
]
} | 9,625 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _mint | function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
| /**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
5370,
5679
]
} | 9,626 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _burn | function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
| /**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
5908,
6219
]
} | 9,627 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _approve | function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
| /**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
6487,
6827
]
} | 9,628 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return A uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Transfer token to a specified address.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses.
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "ERC20: transfer to the zero address");
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _burnFrom | function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
| /**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
7221,
7411
]
} | 9,629 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20Burnable | contract ERC20Burnable is ERC20 {
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of token to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance.
* @param from address The account whose tokens will be burned.
* @param value uint256 The amount of token to be burned.
*/
function burnFrom(address from, uint256 value) public {
_burnFrom(from, value);
}
} | /**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/ | NatSpecMultiLine | burn | function burn(uint256 value) public {
_burn(msg.sender, value);
}
| /**
* @dev Burns a specific amount of tokens.
* @param value The amount of token to be burned.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
156,
240
]
} | 9,630 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20Burnable | contract ERC20Burnable is ERC20 {
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of token to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance.
* @param from address The account whose tokens will be burned.
* @param value uint256 The amount of token to be burned.
*/
function burnFrom(address from, uint256 value) public {
_burnFrom(from, value);
}
} | /**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/ | NatSpecMultiLine | burnFrom | function burnFrom(address from, uint256 value) public {
_burnFrom(from, value);
}
| /**
* @dev Burns a specific amount of tokens from the target address and decrements allowance.
* @param from address The account whose tokens will be burned.
* @param value uint256 The amount of token to be burned.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
490,
590
]
} | 9,631 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | Ownable | contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @return the address of the owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
* @notice Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | owner | function owner() public view returns (address) {
return _owner;
}
| /**
* @return the address of the owner.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
457,
541
]
} | 9,632 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | Ownable | contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @return the address of the owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
* @notice Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | isOwner | function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
| /**
* @return true if `msg.sender` is the owner of the contract.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
828,
925
]
} | 9,633 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | Ownable | contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @return the address of the owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
* @notice Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | renounceOwnership | function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
| /**
* @dev Allows the current owner to relinquish control of the contract.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
* @notice Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
1283,
1428
]
} | 9,634 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | Ownable | contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @return the address of the owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
* @notice Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
| /**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
1600,
1714
]
} | 9,635 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | Ownable | contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @return the address of the owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
* @notice Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | _transferOwnership | function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
| /**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
1859,
2093
]
} | 9,636 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20Detailed | contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @return the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @return the symbol of the token.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @return the number of decimals of the token.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
} | /**
* @title ERC20Detailed token
* @dev The decimals are only for visualization purposes.
* All the operations are done using the smallest and indivisible token unit,
* just as on Ethereum all the operations are done in wei.
*/ | NatSpecMultiLine | name | function name() public view returns (string memory) {
return _name;
}
| /**
* @return the name of the token.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
356,
444
]
} | 9,637 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20Detailed | contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @return the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @return the symbol of the token.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @return the number of decimals of the token.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
} | /**
* @title ERC20Detailed token
* @dev The decimals are only for visualization purposes.
* All the operations are done using the smallest and indivisible token unit,
* just as on Ethereum all the operations are done in wei.
*/ | NatSpecMultiLine | symbol | function symbol() public view returns (string memory) {
return _symbol;
}
| /**
* @return the symbol of the token.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
506,
598
]
} | 9,638 |
|
ERC20Token | ERC20Token.sol | 0x1e13fd454ada4e2a7db75447a0aea6446712028c | Solidity | ERC20Detailed | contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @return the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @return the symbol of the token.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @return the number of decimals of the token.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
} | /**
* @title ERC20Detailed token
* @dev The decimals are only for visualization purposes.
* All the operations are done using the smallest and indivisible token unit,
* just as on Ethereum all the operations are done in wei.
*/ | NatSpecMultiLine | decimals | function decimals() public view returns (uint8) {
return _decimals;
}
| /**
* @return the number of decimals of the token.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | bzzr://e7907a133f4f8e5da9ea47c9b1cccfe4e32f511843247ccd36743d0d0822896b | {
"func_code_index": [
672,
760
]
} | 9,639 |
|
Blitpops | contracts/Blitpops/Blitpops.sol | 0xf9bdddba8011262382182cdfa7c92327aff15279 | Solidity | Blitpops | contract Blitpops is ERC721Enumerable, Ownable, ERC165Storage {
using strings for *;
using Strings for uint256;
struct FilterMatrix {
uint256 revisions;
string filter1;
string filter2;
string filter3;
}
mapping(uint256 => FilterMatrix) internal filterMap;
uint256 public constant MINT_PRICE = 0.02 ether;
uint256 public constant ROYALTY_AMOUNT = 10;
bytes4 private constant _INTERFACE_ID_ERC2981 = 0xc155531d;
address public BLITMAP_ADDRESS;
uint256 public ownerSaleEnd;
bool public editingAllowed;
mapping(string => string) internal filters;
string[] internal filterNames;
constructor(address blitmapAddress) payable ERC721("Blitpop", "BLITPOP") {
_registerInterface(_INTERFACE_ID_ERC2981);
BLITMAP_ADDRESS = blitmapAddress;
filters['og'] = '<svg>';
filters['campbells'] = '<filter id="campbells"><feColorMatrix type="matrix" values="1 0 0 1.9 -2.2 0 1 0 0.0 0.3 0 0 1 0 0.5 0 0 0 1 0.2"></feColorMatrix></filter><svg filter="url(#campbells)">';
filters['electric-chair'] = '<filter id="ec"><feColorMatrix type="matrix" values="1 0 0 0 0 -0.4 1.3 -0.4 0.2 -0.1 0 0 1 0 0 0 0 0 1 0"></feColorMatrix></filter><svg filter="url(#ec)">';
filters['marilyn'] = '<filter id="marilyn"><feColorMatrix type="matrix" values="1 0 0 1.7 -1.6 0 1 0 0.0 0.3 -0.7 0 1 0 0.5 0 0 0 1 0.2"></feColorMatrix></filter><svg filter="url(#marilyn)">';
filters['brillo'] = '<filter id="brillo"><feColorMatrix type="matrix" values="0 1.0 0 0 0 0 1.0 0 0 0 0 0.6 1 0 0 0 0 0 1 0 "/></filter><svg filter="url(#brillo)">';
filters['b&w'] = '<filter id="bw"><feColorMatrix type="matrix" values="0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 "/></filter><svg filter="url(#bw)">';
filterNames = ['og', 'campbells', 'electric-chair', 'marilyn', 'brillo', 'b&w'];
ownerSaleEnd = block.timestamp + 7 days;
}
function addFilter(string memory name, string memory filter) public onlyOwner {
filterNames.push(name);
filters[name] = filter;
}
function setEditingAllowed(bool allowed) public onlyOwner {
editingAllowed = allowed;
}
function listFilters() public view returns(string[] memory) {
return filterNames;
}
function filtersFor(uint256 tokenId) public view returns (FilterMatrix memory) {
return filterMap[tokenId];
}
function ownerMint(
uint256 tokenId,
string memory filter1,
string memory filter2,
string memory filter3) public payable {
if (block.timestamp <= ownerSaleEnd){
require(msg.value == MINT_PRICE, "Bp:oM:402");
require(msg.sender == IBlitmap(BLITMAP_ADDRESS).ownerOf(tokenId), "Bp:oM:403");
}
if (block.timestamp > ownerSaleEnd) {
require(msg.sender == owner(), "Bp:oM:403");
}
filterMap[tokenId] = FilterMatrix({
revisions: 0,
filter1: filter1,
filter2: filter2,
filter3: filter3
});
_safeMint(msg.sender, tokenId);
}
function updateFilters(
uint256 tokenId,
string memory filter1,
string memory filter2,
string memory filter3
) public {
require(editingAllowed, "Bp:uF:400");
require(msg.sender == ownerOf(tokenId), "Bp:uF:403");
filterMap[tokenId] = FilterMatrix({
revisions: filterMap[tokenId].revisions + 1,
filter1: filter1,
filter2: filter2,
filter3: filter3
});
}
/* solhint-disable quotes */
function tokenURI(uint256 tokenId) public view override returns (string memory) {
require(_exists(tokenId), "Bp:tU:404");
FilterMatrix memory tokenFilters = filterMap[tokenId];
return
string(
abi.encodePacked(
"data:application/json;base64,",
Base64.encode(
bytes(
abi.encodePacked(
'{"name":"Blitpop ',
IBlitmap(BLITMAP_ADDRESS).tokenNameOf(tokenId),
'", "description":"Blitpops are onchain Blitmap derivatives. To construct the artwork, the original Blitmap with corresponding token ID is fetched, collaged and filtered to return a modified onchain SVG.", "image": "',
svgBase64Data(tokenId, tokenFilters.filter1, tokenFilters.filter2, tokenFilters.filter3),
'", ',
tokenProperties(tokenFilters),
'"}}'
)
)
)
)
);
}
function tokenProperties(FilterMatrix memory tokenFilters) internal view returns (bytes memory) {
return abi.encodePacked(
'"properties": { "revisions": "',
tokenFilters.revisions.toString(),
'", "Top Right": "',
tokenFilters.filter1,
'", "Bottom Left": "',
tokenFilters.filter2,
'", "Bottom Right": "',
tokenFilters.filter3
);
}
function svgBase64Data(
uint256 tokenId,
string memory filter1,
string memory filter2,
string memory filter3
) public view returns (string memory) {
return string(
abi.encodePacked(
'data:image/svg+xml;base64,',
Base64.encode(svgRaw(tokenId, filter1, filter2, filter3))
)
);
}
function svgRaw(
uint256 tokenId,
string memory filter1,
string memory filter2,
string memory filter3
) internal view returns (bytes memory) {
string memory viewbox = 'viewBox="0 0 32 32">';
strings.slice memory main = IBlitmap(BLITMAP_ADDRESS).tokenSvgDataOf(tokenId).toSlice();
strings.slice memory start = main.split(viewbox.toSlice());
return abi.encodePacked(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><svg viewBox="0 0 32 32" width="32" height="32">',
main.toString(),
'<svg viewBox="0 0 32 32" width="32" height="32" x="32">',
filters[filter1],
main.toString(),
'</svg><svg viewBox="0 0 32 32" width="32" height="32" y="32">',
filters[filter2],
main.toString(),
'</svg><svg viewBox="0 0 32 32" width="32" height="32" x="32" y="32">',
filters[filter3],
main.toString(),
'</svg></svg>'
);
}
function royaltyInfo(
uint256 tokenId,
uint256 value,
bytes calldata _data
) external view returns (address _receiver, uint256 royaltyAmount) {
royaltyAmount = (value * ROYALTY_AMOUNT) / 100;
return (owner(), royaltyAmount);
}
function withdraw() public onlyOwner {
payable(msg.sender).transfer(address(this).balance);
}
function supportsInterface(bytes4 interfaceId) public view override(ERC165Storage, ERC721Enumerable) returns (bool) {
return ERC721Enumerable.supportsInterface(interfaceId) || ERC165Storage.supportsInterface(interfaceId);
}
} | tokenURI | function tokenURI(uint256 tokenId) public view override returns (string memory) {
require(_exists(tokenId), "Bp:tU:404");
FilterMatrix memory tokenFilters = filterMap[tokenId];
return
string(
abi.encodePacked(
"data:application/json;base64,",
Base64.encode(
bytes(
abi.encodePacked(
'{"name":"Blitpop ',
IBlitmap(BLITMAP_ADDRESS).tokenNameOf(tokenId),
'", "description":"Blitpops are onchain Blitmap derivatives. To construct the artwork, the original Blitmap with corresponding token ID is fetched, collaged and filtered to return a modified onchain SVG.", "image": "',
svgBase64Data(tokenId, tokenFilters.filter1, tokenFilters.filter2, tokenFilters.filter3),
'", ',
tokenProperties(tokenFilters),
'"}}'
)
)
)
)
);
}
| /* solhint-disable quotes */ | Comment | v0.8.0+commit.c7dfd78e | {
"func_code_index": [
3641,
4835
]
} | 9,640 |
||||
Token | Token.sol | 0xc169aa542078f044851622e7f5dfa6715631e3fe | Solidity | Token | contract Token {
/* Public variables of the token */
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
/* This generates a public event on the blockchain that will notify clients */
event Transfer(address indexed from, address indexed to, uint256 value);
function Token() {
totalSupply = 10*(10**8)*(10**18);
balanceOf[msg.sender] = 10*(10**8)*(10**18); // Give the creator all initial tokens
name = "MoDous"; // Set the name for display purposes
symbol = "MoDous"; // Set the symbol for display purposes
decimals = 18; // Amount of decimals for display purposes
}
function transfer(address _to, uint256 _value) {
/* Check if sender has balance and for overflows */
if (balanceOf[msg.sender] < _value || balanceOf[_to] + _value < balanceOf[_to])
revert();
/* Add and subtract new balances */
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
/* Notifiy anyone listening that this transfer took place */
Transfer(msg.sender, _to, _value);
}
/* This unnamed function is called whenever someone tries to send ether to it */
function () {
revert(); // Prevents accidental sending of ether
}
} | function () {
revert(); // Prevents accidental sending of ether
}
| /* This unnamed function is called whenever someone tries to send ether to it */ | Comment | v0.4.25+commit.59dbf8f1 | bzzr://982d6fd17fcffc06bed6ab43e9bfee3e2541b27800e15d7afeb587e0e966924d | {
"func_code_index": [
1354,
1429
]
} | 9,641 |
||||
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | name | function name() public view returns (string memory) {
return _name;
}
| /**
* @dev Returns the name of the token.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
902,
990
]
} | 9,642 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | symbol | function symbol() public view returns (string memory) {
return _symbol;
}
| /**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
1104,
1196
]
} | 9,643 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | decimals | function decimals() public view returns (uint8) {
return _decimals;
}
| /**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
1829,
1917
]
} | 9,644 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
| /**
* @dev See {IERC20-totalSupply}.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
1977,
2082
]
} | 9,645 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
| /**
* @dev See {IERC20-balanceOf}.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
2140,
2264
]
} | 9,646 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | transfer | function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
| /**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
2472,
2652
]
} | 9,647 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | allowance | function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
| /**
* @dev See {IERC20-allowance}.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
2710,
2866
]
} | 9,648 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | approve | function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
| /**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
3008,
3182
]
} | 9,649 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
| /**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
3651,
3977
]
} | 9,650 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | increaseAllowance | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
| /**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
4381,
4604
]
} | 9,651 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | decreaseAllowance | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
| /**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
5102,
5376
]
} | 9,652 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _transfer | function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
| /**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
5861,
6405
]
} | 9,653 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _distribute | function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
| /** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
6566,
6967
]
} | 9,654 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _burn | function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
| /**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
7294,
7717
]
} | 9,655 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _approve | function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
| /**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
8152,
8503
]
} | 9,656 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _setupDecimals | function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
| /**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
8830,
8925
]
} | 9,657 |
NJswapToken | @openzeppelin/contracts/token/ERC20/ERC20.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | ERC20 | contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* - `to` cannot be the zero address.
*/
function _distribute(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: unable to do toward the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
} | /**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_distribute}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/ | NatSpecMultiLine | _beforeTokenTransfer | function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
| /**
* @dev Hook that is called before any transfer of tokens.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
9010,
9107
]
} | 9,658 |
R00MToken | R00MToken.sol | 0xad4f86b5e750f324a5c1b5e5954b9a75dd97f844 | Solidity | Context | contract Context {
constructor () internal { }
// solhint-disable-previous-line no-empty-blocks
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
} | _msgSender | function _msgSender() internal view returns (address payable) {
return msg.sender;
}
| // solhint-disable-previous-line no-empty-blocks | LineComment | v0.5.16+commit.9c3226ce | None | bzzr://6c9fdd6db4eecaa82adf8ab9e9a90613fdbd23517cc44b457f61e754dd81530b | {
"func_code_index": [
109,
212
]
} | 9,659 |
||
MINIMANEKINEKO | MINIMANEKINEKO.sol | 0x48749b6b81ec168b27f94baa66a5df0e65855382 | Solidity | MINIMANEKINEKO | contract MINIMANEKINEKO is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
address payable public marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // Marketing Address
address payable public liquidityAddress =
payable(0x000000000000000000000000000000000000dEaD); // Liquidity Address
mapping(address => uint256) private _rOwned;
mapping(address => uint256) private _tOwned;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isExcludedFromFee;
mapping(address => bool) private _isExcluded;
address[] private _excluded;
uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 100 * 1e9 * 1e18;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
string private constant _name = "mini-MANEKI-NEKO";
string private constant _symbol = "miniNEKO";
uint8 private constant _decimals = 18;
uint256 private constant BUY = 1;
uint256 private constant SELL = 2;
uint256 private constant TRANSFER = 3;
uint256 private buyOrSellSwitch;
// these values are pretty much arbitrary since they get overwritten for every txn, but the placeholders make it easier to work with current contract.
uint256 private _taxFee;
uint256 private _previousTaxFee = _taxFee;
uint256 private _liquidityFee;
uint256 private _previousLiquidityFee = _liquidityFee;
uint256 public _buyTaxFee = 0;
uint256 public _buyLiquidityFee = 5;
uint256 public _buyMarketingFee = 0;
uint256 public _sellTaxFee = 0;
uint256 public _sellLiquidityFee = 8;
uint256 public _sellMarketingFee = 7;
uint256 public liquidityActiveBlock = 0; // 0 means liquidity is not active yet
uint256 public tradingActiveBlock = 0; // 0 means trading is not active
bool public limitsInEffect = true;
bool public tradingActive = false;
bool public swapEnabled = false;
mapping (address => bool) public _isExcludedMaxTransactionAmount;
// Anti-bot and anti-whale mappings and variables
mapping(address => uint256) private _holderLastTransferTimestamp; // to hold last Transfers temporarily during launch
bool public transferDelayEnabled = true;
uint256 private _liquidityTokensToSwap;
uint256 private _marketingTokensToSwap;
bool private gasLimitActive = true;
uint256 private gasPriceLimit = 602 * 1 gwei;
// store addresses that a automatic market maker pairs. Any transfer *to* these addresses
// could be subject to a maximum transfer amount
mapping (address => bool) public automatedMarketMakerPairs;
uint256 public minimumTokensBeforeSwap;
uint256 public maxTransactionAmount;
uint256 public maxWallet;
IUniswapV2Router02 public uniswapV2Router;
address public uniswapV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = false;
event RewardLiquidityProviders(uint256 tokenAmount);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
event SwapETHForTokens(uint256 amountIn, address[] path);
event SwapTokensForETH(uint256 amountIn, address[] path);
event ExcludedMaxTransactionAmount(address indexed account, bool isExcluded);
modifier lockTheSwap() {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor() {
address newOwner = msg.sender; // update if auto-deploying to a different wallet
address futureOwner = address(msg.sender); // use if ownership will be transferred after deployment.
maxTransactionAmount = _tTotal * 3 / 1000; // 0.3% max txn
minimumTokensBeforeSwap = _tTotal * 3 / 10000; // 0.03%
maxWallet = _tTotal * 3 / 1000; // .3%
_rOwned[newOwner] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(
// ROPSTEN or HARDHAT
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
);
address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;
uniswapV2Pair = _uniswapV2Pair;
marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // update to marketing address
liquidityAddress = payable(address(0xdead)); // update to a liquidity wallet if you don't want to burn LP tokens generated by the contract.
_setAutomatedMarketMakerPair(_uniswapV2Pair, true);
_isExcludedFromFee[newOwner] = true;
_isExcludedFromFee[futureOwner] = true; // pre-exclude future owner wallet
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[liquidityAddress] = true;
excludeFromMaxTransaction(newOwner, true);
excludeFromMaxTransaction(futureOwner, true); // pre-exclude future owner wallet
excludeFromMaxTransaction(address(this), true);
excludeFromMaxTransaction(address(_uniswapV2Router), true);
excludeFromMaxTransaction(address(0xdead), true);
emit Transfer(address(0), newOwner, _tTotal);
}
function name() external pure returns (string memory) {
return _name;
}
function symbol() external pure returns (string memory) {
return _symbol;
}
function decimals() external pure returns (uint8) {
return _decimals;
}
function totalSupply() external pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount)
external
override
returns (bool)
{
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender)
external
view
override
returns (uint256)
{
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount)
public
override
returns (bool)
{
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()].sub(
amount,
"ERC20: transfer amount exceeds allowance"
)
);
return true;
}
function increaseAllowance(address spender, uint256 addedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].add(addedValue)
);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].sub(
subtractedValue,
"ERC20: decreased allowance below zero"
)
);
return true;
}
function isExcludedFromReward(address account)
external
view
returns (bool)
{
return _isExcluded[account];
}
function totalFees() external view returns (uint256) {
return _tFeeTotal;
}
// once enabled, can never be turned off
function enableTrading() external onlyOwner {
tradingActive = true;
swapAndLiquifyEnabled = true;
tradingActiveBlock = block.number;
}
function minimumTokensBeforeSwapAmount() external view returns (uint256) {
return minimumTokensBeforeSwap;
}
function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner {
require(pair != uniswapV2Pair, "The pair cannot be removed from automatedMarketMakerPairs");
_setAutomatedMarketMakerPair(pair, value);
}
function _setAutomatedMarketMakerPair(address pair, bool value) private {
automatedMarketMakerPairs[pair] = value;
excludeFromMaxTransaction(pair, value);
if(value){excludeFromReward(pair);}
if(!value){includeInReward(pair);}
}
function setProtectionSettings(bool antiGas) external onlyOwner() {
gasLimitActive = antiGas;
}
function setGasPriceLimit(uint256 gas) external onlyOwner {
require(gas >= 300);
gasPriceLimit = gas * 1 gwei;
}
// disable Transfer delay
function disableTransferDelay() external onlyOwner returns (bool){
transferDelayEnabled = false;
return true;
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee)
external
view
returns (uint256)
{
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount, , , , , ) = _getValues(tAmount);
return rAmount;
} else {
(, uint256 rTransferAmount, , , , ) = _getValues(tAmount);
return rTransferAmount;
}
}
// remove limits after token is stable - 30-60 minutes
function removeLimits() external onlyOwner returns (bool){
limitsInEffect = false;
gasLimitActive = false;
transferDelayEnabled = false;
return true;
}
function tokenFromReflection(uint256 rAmount)
public
view
returns (uint256)
{
require(
rAmount <= _rTotal,
"Amount must be less than total reflections"
);
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeFromReward(address account) public onlyOwner {
require(!_isExcluded[account], "Account is already excluded");
require(_excluded.length + 1 <= 50, "Cannot exclude more than 50 accounts. Include a previously excluded address.");
if (_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function excludeFromMaxTransaction(address updAds, bool isEx) public onlyOwner {
_isExcludedMaxTransactionAmount[updAds] = isEx;
emit ExcludedMaxTransactionAmount(updAds, isEx);
}
function includeInReward(address account) public onlyOwner {
require(_isExcluded[account], "Account is not excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function _approve(
address owner,
address spender,
uint256 amount
) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(
address from,
address to,
uint256 amount
) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(!tradingActive){
require(_isExcludedFromFee[from] || _isExcludedFromFee[to], "Trading is not active yet.");
}
if(limitsInEffect){
if (
from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead) &&
!inSwapAndLiquify
){
// only use to prevent sniper buys in the first blocks.
if (gasLimitActive && automatedMarketMakerPairs[from]) {
require(tx.gasprice <= gasPriceLimit, "Gas price exceeds limit.");
}
// at launch if the transfer delay is enabled, ensure the block timestamps for purchasers is set -- during launch.
if (transferDelayEnabled){
if (to != owner() && to != address(uniswapV2Router) && to != address(uniswapV2Pair)){
require(_holderLastTransferTimestamp[tx.origin] < block.number, "_transfer:: Transfer Delay enabled. Only one purchase per block allowed.");
_holderLastTransferTimestamp[tx.origin] = block.number;
}
}
//when buy
if (automatedMarketMakerPairs[from] && !_isExcludedMaxTransactionAmount[to]) {
require(amount <= maxTransactionAmount, "Buy transfer amount exceeds the maxTransactionAmount.");
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
//when sell
else if (automatedMarketMakerPairs[to] && !_isExcludedMaxTransactionAmount[from]) {
require(amount <= maxTransactionAmount, "Sell transfer amount exceeds the maxTransactionAmount.");
}
else if (!_isExcludedMaxTransactionAmount[to]){
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
}
}
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinimumTokenBalance = contractTokenBalance >=
minimumTokensBeforeSwap;
// Sell tokens for ETH
if (
!inSwapAndLiquify &&
swapAndLiquifyEnabled &&
balanceOf(uniswapV2Pair) > 0 &&
overMinimumTokenBalance &&
automatedMarketMakerPairs[to]
) {
swapBack();
}
removeAllFee();
buyOrSellSwitch = TRANSFER;
// If any account belongs to _isExcludedFromFee account then remove the fee
if (!_isExcludedFromFee[from] && !_isExcludedFromFee[to]) {
// Buy
if (automatedMarketMakerPairs[from]) {
_taxFee = _buyTaxFee;
_liquidityFee = _buyLiquidityFee + _buyMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = BUY;
}
}
// Sell
else if (automatedMarketMakerPairs[to]) {
_taxFee = _sellTaxFee;
_liquidityFee = _sellLiquidityFee + _sellMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = SELL;
}
}
}
_tokenTransfer(from, to, amount);
restoreAllFee();
}
function swapBack() private lockTheSwap {
uint256 contractBalance = balanceOf(address(this));
bool success;
uint256 totalTokensToSwap = _liquidityTokensToSwap + _marketingTokensToSwap;
if(totalTokensToSwap == 0 || contractBalance == 0) {return;}
// Halve the amount of liquidity tokens
uint256 tokensForLiquidity = (contractBalance * _liquidityTokensToSwap / totalTokensToSwap) / 2;
uint256 amountToSwapForBNB = contractBalance.sub(tokensForLiquidity);
uint256 initialBNBBalance = address(this).balance;
swapTokensForBNB(amountToSwapForBNB);
uint256 bnbBalance = address(this).balance.sub(initialBNBBalance);
uint256 bnbForMarketing = bnbBalance.mul(_marketingTokensToSwap).div(totalTokensToSwap);
uint256 bnbForLiquidity = bnbBalance - bnbForMarketing;
_liquidityTokensToSwap = 0;
_marketingTokensToSwap = 0;
if(tokensForLiquidity > 0 && bnbForLiquidity > 0){
addLiquidity(tokensForLiquidity, bnbForLiquidity);
emit SwapAndLiquify(amountToSwapForBNB, bnbForLiquidity, tokensForLiquidity);
}
(success,) = address(marketingAddress).call{value: address(this).balance}("");
}
function swapTokensForBNB(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
liquidityAddress,
block.timestamp
);
}
function _tokenTransfer(
address sender,
address recipient,
uint256 amount
) private {
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
}
function _transferStandard(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferBothExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
function _getValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256,
uint256,
uint256,
uint256
)
{
(
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(
tAmount,
tFee,
tLiquidity,
_getRate()
);
return (
rAmount,
rTransferAmount,
rFee,
tTransferAmount,
tFee,
tLiquidity
);
}
function _getTValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256
)
{
uint256 tFee = calculateTaxFee(tAmount);
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
return (tTransferAmount, tFee, tLiquidity);
}
function _getRValues(
uint256 tAmount,
uint256 tFee,
uint256 tLiquidity,
uint256 currentRate
)
private
pure
returns (
uint256,
uint256,
uint256
)
{
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rLiquidity = tLiquidity.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns (uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns (uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (
_rOwned[_excluded[i]] > rSupply ||
_tOwned[_excluded[i]] > tSupply
) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _takeLiquidity(uint256 tLiquidity) private {
if(buyOrSellSwitch == BUY){
_liquidityTokensToSwap += tLiquidity * _buyLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _buyMarketingFee / _liquidityFee;
} else if(buyOrSellSwitch == SELL){
_liquidityTokensToSwap += tLiquidity * _sellLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _sellMarketingFee / _liquidityFee;
}
uint256 currentRate = _getRate();
uint256 rLiquidity = tLiquidity.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
if (_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(10**2);
}
function calculateLiquidityFee(uint256 _amount)
private
view
returns (uint256)
{
return _amount.mul(_liquidityFee).div(10**2);
}
function removeAllFee() private {
if (_taxFee == 0 && _liquidityFee == 0) return;
_previousTaxFee = _taxFee;
_previousLiquidityFee = _liquidityFee;
_taxFee = 0;
_liquidityFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_liquidityFee = _previousLiquidityFee;
}
function isExcludedFromFee(address account) external view returns (bool) {
return _isExcludedFromFee[account];
}
function excludeFromFee(address account) external onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) external onlyOwner {
_isExcludedFromFee[account] = false;
}
function setBuyFee(uint256 buyTaxFee, uint256 buyLiquidityFee, uint256 buyMarketingFee)
external
onlyOwner
{
_buyTaxFee = buyTaxFee;
_buyLiquidityFee = buyLiquidityFee;
_buyMarketingFee = buyMarketingFee;
require(_buyTaxFee + _buyLiquidityFee + _buyMarketingFee <= 20, "Must keep taxes below 20%");
}
function setSellFee(uint256 sellTaxFee, uint256 sellLiquidityFee, uint256 sellMarketingFee)
external
onlyOwner
{
_sellTaxFee = sellTaxFee;
_sellLiquidityFee = sellLiquidityFee;
_sellMarketingFee = sellMarketingFee;
require(_sellTaxFee + _sellLiquidityFee + _sellMarketingFee <= 30, "Must keep taxes below 30%");
}
function setMarketingAddress(address _marketingAddress) external onlyOwner {
marketingAddress = payable(_marketingAddress);
_isExcludedFromFee[marketingAddress] = true;
}
function setLiquidityAddress(address _liquidityAddress) external onlyOwner {
liquidityAddress = payable(_liquidityAddress);
_isExcludedFromFee[liquidityAddress] = true;
}
function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
// useful for buybacks or to reclaim any BNB on the contract in a way that helps holders.
function buyBackTokens(uint256 bnbAmountInWei) external onlyOwner {
// generate the uniswap pair path of weth -> eth
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
// make the swap
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: bnbAmountInWei}(
0, // accept any amount of Ethereum
path,
address(0xdead),
block.timestamp
);
}
// To receive ETH from uniswapV2Router when swapping
receive() external payable {}
function transferForeignToken(address _token, address _to)
external
onlyOwner
returns (bool _sent)
{
require(_token != address(this), "Can't withdraw native tokens");
uint256 _contractBalance = IERC20(_token).balanceOf(address(this));
_sent = IERC20(_token).transfer(_to, _contractBalance);
}
} | enableTrading | function enableTrading() external onlyOwner {
tradingActive = true;
swapAndLiquifyEnabled = true;
tradingActiveBlock = block.number;
}
| // once enabled, can never be turned off | LineComment | v0.8.9+commit.e5eed63a | None | ipfs://ab890a60740e4b9b0482010b3d9ce59818bbb6af2d1c9e9d588b1854bf2f3a6c | {
"func_code_index": [
8138,
8309
]
} | 9,660 |
||
MINIMANEKINEKO | MINIMANEKINEKO.sol | 0x48749b6b81ec168b27f94baa66a5df0e65855382 | Solidity | MINIMANEKINEKO | contract MINIMANEKINEKO is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
address payable public marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // Marketing Address
address payable public liquidityAddress =
payable(0x000000000000000000000000000000000000dEaD); // Liquidity Address
mapping(address => uint256) private _rOwned;
mapping(address => uint256) private _tOwned;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isExcludedFromFee;
mapping(address => bool) private _isExcluded;
address[] private _excluded;
uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 100 * 1e9 * 1e18;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
string private constant _name = "mini-MANEKI-NEKO";
string private constant _symbol = "miniNEKO";
uint8 private constant _decimals = 18;
uint256 private constant BUY = 1;
uint256 private constant SELL = 2;
uint256 private constant TRANSFER = 3;
uint256 private buyOrSellSwitch;
// these values are pretty much arbitrary since they get overwritten for every txn, but the placeholders make it easier to work with current contract.
uint256 private _taxFee;
uint256 private _previousTaxFee = _taxFee;
uint256 private _liquidityFee;
uint256 private _previousLiquidityFee = _liquidityFee;
uint256 public _buyTaxFee = 0;
uint256 public _buyLiquidityFee = 5;
uint256 public _buyMarketingFee = 0;
uint256 public _sellTaxFee = 0;
uint256 public _sellLiquidityFee = 8;
uint256 public _sellMarketingFee = 7;
uint256 public liquidityActiveBlock = 0; // 0 means liquidity is not active yet
uint256 public tradingActiveBlock = 0; // 0 means trading is not active
bool public limitsInEffect = true;
bool public tradingActive = false;
bool public swapEnabled = false;
mapping (address => bool) public _isExcludedMaxTransactionAmount;
// Anti-bot and anti-whale mappings and variables
mapping(address => uint256) private _holderLastTransferTimestamp; // to hold last Transfers temporarily during launch
bool public transferDelayEnabled = true;
uint256 private _liquidityTokensToSwap;
uint256 private _marketingTokensToSwap;
bool private gasLimitActive = true;
uint256 private gasPriceLimit = 602 * 1 gwei;
// store addresses that a automatic market maker pairs. Any transfer *to* these addresses
// could be subject to a maximum transfer amount
mapping (address => bool) public automatedMarketMakerPairs;
uint256 public minimumTokensBeforeSwap;
uint256 public maxTransactionAmount;
uint256 public maxWallet;
IUniswapV2Router02 public uniswapV2Router;
address public uniswapV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = false;
event RewardLiquidityProviders(uint256 tokenAmount);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
event SwapETHForTokens(uint256 amountIn, address[] path);
event SwapTokensForETH(uint256 amountIn, address[] path);
event ExcludedMaxTransactionAmount(address indexed account, bool isExcluded);
modifier lockTheSwap() {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor() {
address newOwner = msg.sender; // update if auto-deploying to a different wallet
address futureOwner = address(msg.sender); // use if ownership will be transferred after deployment.
maxTransactionAmount = _tTotal * 3 / 1000; // 0.3% max txn
minimumTokensBeforeSwap = _tTotal * 3 / 10000; // 0.03%
maxWallet = _tTotal * 3 / 1000; // .3%
_rOwned[newOwner] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(
// ROPSTEN or HARDHAT
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
);
address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;
uniswapV2Pair = _uniswapV2Pair;
marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // update to marketing address
liquidityAddress = payable(address(0xdead)); // update to a liquidity wallet if you don't want to burn LP tokens generated by the contract.
_setAutomatedMarketMakerPair(_uniswapV2Pair, true);
_isExcludedFromFee[newOwner] = true;
_isExcludedFromFee[futureOwner] = true; // pre-exclude future owner wallet
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[liquidityAddress] = true;
excludeFromMaxTransaction(newOwner, true);
excludeFromMaxTransaction(futureOwner, true); // pre-exclude future owner wallet
excludeFromMaxTransaction(address(this), true);
excludeFromMaxTransaction(address(_uniswapV2Router), true);
excludeFromMaxTransaction(address(0xdead), true);
emit Transfer(address(0), newOwner, _tTotal);
}
function name() external pure returns (string memory) {
return _name;
}
function symbol() external pure returns (string memory) {
return _symbol;
}
function decimals() external pure returns (uint8) {
return _decimals;
}
function totalSupply() external pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount)
external
override
returns (bool)
{
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender)
external
view
override
returns (uint256)
{
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount)
public
override
returns (bool)
{
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()].sub(
amount,
"ERC20: transfer amount exceeds allowance"
)
);
return true;
}
function increaseAllowance(address spender, uint256 addedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].add(addedValue)
);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].sub(
subtractedValue,
"ERC20: decreased allowance below zero"
)
);
return true;
}
function isExcludedFromReward(address account)
external
view
returns (bool)
{
return _isExcluded[account];
}
function totalFees() external view returns (uint256) {
return _tFeeTotal;
}
// once enabled, can never be turned off
function enableTrading() external onlyOwner {
tradingActive = true;
swapAndLiquifyEnabled = true;
tradingActiveBlock = block.number;
}
function minimumTokensBeforeSwapAmount() external view returns (uint256) {
return minimumTokensBeforeSwap;
}
function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner {
require(pair != uniswapV2Pair, "The pair cannot be removed from automatedMarketMakerPairs");
_setAutomatedMarketMakerPair(pair, value);
}
function _setAutomatedMarketMakerPair(address pair, bool value) private {
automatedMarketMakerPairs[pair] = value;
excludeFromMaxTransaction(pair, value);
if(value){excludeFromReward(pair);}
if(!value){includeInReward(pair);}
}
function setProtectionSettings(bool antiGas) external onlyOwner() {
gasLimitActive = antiGas;
}
function setGasPriceLimit(uint256 gas) external onlyOwner {
require(gas >= 300);
gasPriceLimit = gas * 1 gwei;
}
// disable Transfer delay
function disableTransferDelay() external onlyOwner returns (bool){
transferDelayEnabled = false;
return true;
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee)
external
view
returns (uint256)
{
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount, , , , , ) = _getValues(tAmount);
return rAmount;
} else {
(, uint256 rTransferAmount, , , , ) = _getValues(tAmount);
return rTransferAmount;
}
}
// remove limits after token is stable - 30-60 minutes
function removeLimits() external onlyOwner returns (bool){
limitsInEffect = false;
gasLimitActive = false;
transferDelayEnabled = false;
return true;
}
function tokenFromReflection(uint256 rAmount)
public
view
returns (uint256)
{
require(
rAmount <= _rTotal,
"Amount must be less than total reflections"
);
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeFromReward(address account) public onlyOwner {
require(!_isExcluded[account], "Account is already excluded");
require(_excluded.length + 1 <= 50, "Cannot exclude more than 50 accounts. Include a previously excluded address.");
if (_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function excludeFromMaxTransaction(address updAds, bool isEx) public onlyOwner {
_isExcludedMaxTransactionAmount[updAds] = isEx;
emit ExcludedMaxTransactionAmount(updAds, isEx);
}
function includeInReward(address account) public onlyOwner {
require(_isExcluded[account], "Account is not excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function _approve(
address owner,
address spender,
uint256 amount
) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(
address from,
address to,
uint256 amount
) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(!tradingActive){
require(_isExcludedFromFee[from] || _isExcludedFromFee[to], "Trading is not active yet.");
}
if(limitsInEffect){
if (
from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead) &&
!inSwapAndLiquify
){
// only use to prevent sniper buys in the first blocks.
if (gasLimitActive && automatedMarketMakerPairs[from]) {
require(tx.gasprice <= gasPriceLimit, "Gas price exceeds limit.");
}
// at launch if the transfer delay is enabled, ensure the block timestamps for purchasers is set -- during launch.
if (transferDelayEnabled){
if (to != owner() && to != address(uniswapV2Router) && to != address(uniswapV2Pair)){
require(_holderLastTransferTimestamp[tx.origin] < block.number, "_transfer:: Transfer Delay enabled. Only one purchase per block allowed.");
_holderLastTransferTimestamp[tx.origin] = block.number;
}
}
//when buy
if (automatedMarketMakerPairs[from] && !_isExcludedMaxTransactionAmount[to]) {
require(amount <= maxTransactionAmount, "Buy transfer amount exceeds the maxTransactionAmount.");
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
//when sell
else if (automatedMarketMakerPairs[to] && !_isExcludedMaxTransactionAmount[from]) {
require(amount <= maxTransactionAmount, "Sell transfer amount exceeds the maxTransactionAmount.");
}
else if (!_isExcludedMaxTransactionAmount[to]){
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
}
}
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinimumTokenBalance = contractTokenBalance >=
minimumTokensBeforeSwap;
// Sell tokens for ETH
if (
!inSwapAndLiquify &&
swapAndLiquifyEnabled &&
balanceOf(uniswapV2Pair) > 0 &&
overMinimumTokenBalance &&
automatedMarketMakerPairs[to]
) {
swapBack();
}
removeAllFee();
buyOrSellSwitch = TRANSFER;
// If any account belongs to _isExcludedFromFee account then remove the fee
if (!_isExcludedFromFee[from] && !_isExcludedFromFee[to]) {
// Buy
if (automatedMarketMakerPairs[from]) {
_taxFee = _buyTaxFee;
_liquidityFee = _buyLiquidityFee + _buyMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = BUY;
}
}
// Sell
else if (automatedMarketMakerPairs[to]) {
_taxFee = _sellTaxFee;
_liquidityFee = _sellLiquidityFee + _sellMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = SELL;
}
}
}
_tokenTransfer(from, to, amount);
restoreAllFee();
}
function swapBack() private lockTheSwap {
uint256 contractBalance = balanceOf(address(this));
bool success;
uint256 totalTokensToSwap = _liquidityTokensToSwap + _marketingTokensToSwap;
if(totalTokensToSwap == 0 || contractBalance == 0) {return;}
// Halve the amount of liquidity tokens
uint256 tokensForLiquidity = (contractBalance * _liquidityTokensToSwap / totalTokensToSwap) / 2;
uint256 amountToSwapForBNB = contractBalance.sub(tokensForLiquidity);
uint256 initialBNBBalance = address(this).balance;
swapTokensForBNB(amountToSwapForBNB);
uint256 bnbBalance = address(this).balance.sub(initialBNBBalance);
uint256 bnbForMarketing = bnbBalance.mul(_marketingTokensToSwap).div(totalTokensToSwap);
uint256 bnbForLiquidity = bnbBalance - bnbForMarketing;
_liquidityTokensToSwap = 0;
_marketingTokensToSwap = 0;
if(tokensForLiquidity > 0 && bnbForLiquidity > 0){
addLiquidity(tokensForLiquidity, bnbForLiquidity);
emit SwapAndLiquify(amountToSwapForBNB, bnbForLiquidity, tokensForLiquidity);
}
(success,) = address(marketingAddress).call{value: address(this).balance}("");
}
function swapTokensForBNB(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
liquidityAddress,
block.timestamp
);
}
function _tokenTransfer(
address sender,
address recipient,
uint256 amount
) private {
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
}
function _transferStandard(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferBothExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
function _getValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256,
uint256,
uint256,
uint256
)
{
(
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(
tAmount,
tFee,
tLiquidity,
_getRate()
);
return (
rAmount,
rTransferAmount,
rFee,
tTransferAmount,
tFee,
tLiquidity
);
}
function _getTValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256
)
{
uint256 tFee = calculateTaxFee(tAmount);
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
return (tTransferAmount, tFee, tLiquidity);
}
function _getRValues(
uint256 tAmount,
uint256 tFee,
uint256 tLiquidity,
uint256 currentRate
)
private
pure
returns (
uint256,
uint256,
uint256
)
{
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rLiquidity = tLiquidity.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns (uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns (uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (
_rOwned[_excluded[i]] > rSupply ||
_tOwned[_excluded[i]] > tSupply
) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _takeLiquidity(uint256 tLiquidity) private {
if(buyOrSellSwitch == BUY){
_liquidityTokensToSwap += tLiquidity * _buyLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _buyMarketingFee / _liquidityFee;
} else if(buyOrSellSwitch == SELL){
_liquidityTokensToSwap += tLiquidity * _sellLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _sellMarketingFee / _liquidityFee;
}
uint256 currentRate = _getRate();
uint256 rLiquidity = tLiquidity.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
if (_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(10**2);
}
function calculateLiquidityFee(uint256 _amount)
private
view
returns (uint256)
{
return _amount.mul(_liquidityFee).div(10**2);
}
function removeAllFee() private {
if (_taxFee == 0 && _liquidityFee == 0) return;
_previousTaxFee = _taxFee;
_previousLiquidityFee = _liquidityFee;
_taxFee = 0;
_liquidityFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_liquidityFee = _previousLiquidityFee;
}
function isExcludedFromFee(address account) external view returns (bool) {
return _isExcludedFromFee[account];
}
function excludeFromFee(address account) external onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) external onlyOwner {
_isExcludedFromFee[account] = false;
}
function setBuyFee(uint256 buyTaxFee, uint256 buyLiquidityFee, uint256 buyMarketingFee)
external
onlyOwner
{
_buyTaxFee = buyTaxFee;
_buyLiquidityFee = buyLiquidityFee;
_buyMarketingFee = buyMarketingFee;
require(_buyTaxFee + _buyLiquidityFee + _buyMarketingFee <= 20, "Must keep taxes below 20%");
}
function setSellFee(uint256 sellTaxFee, uint256 sellLiquidityFee, uint256 sellMarketingFee)
external
onlyOwner
{
_sellTaxFee = sellTaxFee;
_sellLiquidityFee = sellLiquidityFee;
_sellMarketingFee = sellMarketingFee;
require(_sellTaxFee + _sellLiquidityFee + _sellMarketingFee <= 30, "Must keep taxes below 30%");
}
function setMarketingAddress(address _marketingAddress) external onlyOwner {
marketingAddress = payable(_marketingAddress);
_isExcludedFromFee[marketingAddress] = true;
}
function setLiquidityAddress(address _liquidityAddress) external onlyOwner {
liquidityAddress = payable(_liquidityAddress);
_isExcludedFromFee[liquidityAddress] = true;
}
function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
// useful for buybacks or to reclaim any BNB on the contract in a way that helps holders.
function buyBackTokens(uint256 bnbAmountInWei) external onlyOwner {
// generate the uniswap pair path of weth -> eth
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
// make the swap
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: bnbAmountInWei}(
0, // accept any amount of Ethereum
path,
address(0xdead),
block.timestamp
);
}
// To receive ETH from uniswapV2Router when swapping
receive() external payable {}
function transferForeignToken(address _token, address _to)
external
onlyOwner
returns (bool _sent)
{
require(_token != address(this), "Can't withdraw native tokens");
uint256 _contractBalance = IERC20(_token).balanceOf(address(this));
_sent = IERC20(_token).transfer(_to, _contractBalance);
}
} | disableTransferDelay | function disableTransferDelay() external onlyOwner returns (bool){
transferDelayEnabled = false;
return true;
}
| // disable Transfer delay | LineComment | v0.8.9+commit.e5eed63a | None | ipfs://ab890a60740e4b9b0482010b3d9ce59818bbb6af2d1c9e9d588b1854bf2f3a6c | {
"func_code_index": [
9263,
9402
]
} | 9,661 |
||
MINIMANEKINEKO | MINIMANEKINEKO.sol | 0x48749b6b81ec168b27f94baa66a5df0e65855382 | Solidity | MINIMANEKINEKO | contract MINIMANEKINEKO is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
address payable public marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // Marketing Address
address payable public liquidityAddress =
payable(0x000000000000000000000000000000000000dEaD); // Liquidity Address
mapping(address => uint256) private _rOwned;
mapping(address => uint256) private _tOwned;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isExcludedFromFee;
mapping(address => bool) private _isExcluded;
address[] private _excluded;
uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 100 * 1e9 * 1e18;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
string private constant _name = "mini-MANEKI-NEKO";
string private constant _symbol = "miniNEKO";
uint8 private constant _decimals = 18;
uint256 private constant BUY = 1;
uint256 private constant SELL = 2;
uint256 private constant TRANSFER = 3;
uint256 private buyOrSellSwitch;
// these values are pretty much arbitrary since they get overwritten for every txn, but the placeholders make it easier to work with current contract.
uint256 private _taxFee;
uint256 private _previousTaxFee = _taxFee;
uint256 private _liquidityFee;
uint256 private _previousLiquidityFee = _liquidityFee;
uint256 public _buyTaxFee = 0;
uint256 public _buyLiquidityFee = 5;
uint256 public _buyMarketingFee = 0;
uint256 public _sellTaxFee = 0;
uint256 public _sellLiquidityFee = 8;
uint256 public _sellMarketingFee = 7;
uint256 public liquidityActiveBlock = 0; // 0 means liquidity is not active yet
uint256 public tradingActiveBlock = 0; // 0 means trading is not active
bool public limitsInEffect = true;
bool public tradingActive = false;
bool public swapEnabled = false;
mapping (address => bool) public _isExcludedMaxTransactionAmount;
// Anti-bot and anti-whale mappings and variables
mapping(address => uint256) private _holderLastTransferTimestamp; // to hold last Transfers temporarily during launch
bool public transferDelayEnabled = true;
uint256 private _liquidityTokensToSwap;
uint256 private _marketingTokensToSwap;
bool private gasLimitActive = true;
uint256 private gasPriceLimit = 602 * 1 gwei;
// store addresses that a automatic market maker pairs. Any transfer *to* these addresses
// could be subject to a maximum transfer amount
mapping (address => bool) public automatedMarketMakerPairs;
uint256 public minimumTokensBeforeSwap;
uint256 public maxTransactionAmount;
uint256 public maxWallet;
IUniswapV2Router02 public uniswapV2Router;
address public uniswapV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = false;
event RewardLiquidityProviders(uint256 tokenAmount);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
event SwapETHForTokens(uint256 amountIn, address[] path);
event SwapTokensForETH(uint256 amountIn, address[] path);
event ExcludedMaxTransactionAmount(address indexed account, bool isExcluded);
modifier lockTheSwap() {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor() {
address newOwner = msg.sender; // update if auto-deploying to a different wallet
address futureOwner = address(msg.sender); // use if ownership will be transferred after deployment.
maxTransactionAmount = _tTotal * 3 / 1000; // 0.3% max txn
minimumTokensBeforeSwap = _tTotal * 3 / 10000; // 0.03%
maxWallet = _tTotal * 3 / 1000; // .3%
_rOwned[newOwner] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(
// ROPSTEN or HARDHAT
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
);
address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;
uniswapV2Pair = _uniswapV2Pair;
marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // update to marketing address
liquidityAddress = payable(address(0xdead)); // update to a liquidity wallet if you don't want to burn LP tokens generated by the contract.
_setAutomatedMarketMakerPair(_uniswapV2Pair, true);
_isExcludedFromFee[newOwner] = true;
_isExcludedFromFee[futureOwner] = true; // pre-exclude future owner wallet
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[liquidityAddress] = true;
excludeFromMaxTransaction(newOwner, true);
excludeFromMaxTransaction(futureOwner, true); // pre-exclude future owner wallet
excludeFromMaxTransaction(address(this), true);
excludeFromMaxTransaction(address(_uniswapV2Router), true);
excludeFromMaxTransaction(address(0xdead), true);
emit Transfer(address(0), newOwner, _tTotal);
}
function name() external pure returns (string memory) {
return _name;
}
function symbol() external pure returns (string memory) {
return _symbol;
}
function decimals() external pure returns (uint8) {
return _decimals;
}
function totalSupply() external pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount)
external
override
returns (bool)
{
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender)
external
view
override
returns (uint256)
{
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount)
public
override
returns (bool)
{
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()].sub(
amount,
"ERC20: transfer amount exceeds allowance"
)
);
return true;
}
function increaseAllowance(address spender, uint256 addedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].add(addedValue)
);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].sub(
subtractedValue,
"ERC20: decreased allowance below zero"
)
);
return true;
}
function isExcludedFromReward(address account)
external
view
returns (bool)
{
return _isExcluded[account];
}
function totalFees() external view returns (uint256) {
return _tFeeTotal;
}
// once enabled, can never be turned off
function enableTrading() external onlyOwner {
tradingActive = true;
swapAndLiquifyEnabled = true;
tradingActiveBlock = block.number;
}
function minimumTokensBeforeSwapAmount() external view returns (uint256) {
return minimumTokensBeforeSwap;
}
function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner {
require(pair != uniswapV2Pair, "The pair cannot be removed from automatedMarketMakerPairs");
_setAutomatedMarketMakerPair(pair, value);
}
function _setAutomatedMarketMakerPair(address pair, bool value) private {
automatedMarketMakerPairs[pair] = value;
excludeFromMaxTransaction(pair, value);
if(value){excludeFromReward(pair);}
if(!value){includeInReward(pair);}
}
function setProtectionSettings(bool antiGas) external onlyOwner() {
gasLimitActive = antiGas;
}
function setGasPriceLimit(uint256 gas) external onlyOwner {
require(gas >= 300);
gasPriceLimit = gas * 1 gwei;
}
// disable Transfer delay
function disableTransferDelay() external onlyOwner returns (bool){
transferDelayEnabled = false;
return true;
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee)
external
view
returns (uint256)
{
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount, , , , , ) = _getValues(tAmount);
return rAmount;
} else {
(, uint256 rTransferAmount, , , , ) = _getValues(tAmount);
return rTransferAmount;
}
}
// remove limits after token is stable - 30-60 minutes
function removeLimits() external onlyOwner returns (bool){
limitsInEffect = false;
gasLimitActive = false;
transferDelayEnabled = false;
return true;
}
function tokenFromReflection(uint256 rAmount)
public
view
returns (uint256)
{
require(
rAmount <= _rTotal,
"Amount must be less than total reflections"
);
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeFromReward(address account) public onlyOwner {
require(!_isExcluded[account], "Account is already excluded");
require(_excluded.length + 1 <= 50, "Cannot exclude more than 50 accounts. Include a previously excluded address.");
if (_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function excludeFromMaxTransaction(address updAds, bool isEx) public onlyOwner {
_isExcludedMaxTransactionAmount[updAds] = isEx;
emit ExcludedMaxTransactionAmount(updAds, isEx);
}
function includeInReward(address account) public onlyOwner {
require(_isExcluded[account], "Account is not excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function _approve(
address owner,
address spender,
uint256 amount
) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(
address from,
address to,
uint256 amount
) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(!tradingActive){
require(_isExcludedFromFee[from] || _isExcludedFromFee[to], "Trading is not active yet.");
}
if(limitsInEffect){
if (
from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead) &&
!inSwapAndLiquify
){
// only use to prevent sniper buys in the first blocks.
if (gasLimitActive && automatedMarketMakerPairs[from]) {
require(tx.gasprice <= gasPriceLimit, "Gas price exceeds limit.");
}
// at launch if the transfer delay is enabled, ensure the block timestamps for purchasers is set -- during launch.
if (transferDelayEnabled){
if (to != owner() && to != address(uniswapV2Router) && to != address(uniswapV2Pair)){
require(_holderLastTransferTimestamp[tx.origin] < block.number, "_transfer:: Transfer Delay enabled. Only one purchase per block allowed.");
_holderLastTransferTimestamp[tx.origin] = block.number;
}
}
//when buy
if (automatedMarketMakerPairs[from] && !_isExcludedMaxTransactionAmount[to]) {
require(amount <= maxTransactionAmount, "Buy transfer amount exceeds the maxTransactionAmount.");
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
//when sell
else if (automatedMarketMakerPairs[to] && !_isExcludedMaxTransactionAmount[from]) {
require(amount <= maxTransactionAmount, "Sell transfer amount exceeds the maxTransactionAmount.");
}
else if (!_isExcludedMaxTransactionAmount[to]){
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
}
}
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinimumTokenBalance = contractTokenBalance >=
minimumTokensBeforeSwap;
// Sell tokens for ETH
if (
!inSwapAndLiquify &&
swapAndLiquifyEnabled &&
balanceOf(uniswapV2Pair) > 0 &&
overMinimumTokenBalance &&
automatedMarketMakerPairs[to]
) {
swapBack();
}
removeAllFee();
buyOrSellSwitch = TRANSFER;
// If any account belongs to _isExcludedFromFee account then remove the fee
if (!_isExcludedFromFee[from] && !_isExcludedFromFee[to]) {
// Buy
if (automatedMarketMakerPairs[from]) {
_taxFee = _buyTaxFee;
_liquidityFee = _buyLiquidityFee + _buyMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = BUY;
}
}
// Sell
else if (automatedMarketMakerPairs[to]) {
_taxFee = _sellTaxFee;
_liquidityFee = _sellLiquidityFee + _sellMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = SELL;
}
}
}
_tokenTransfer(from, to, amount);
restoreAllFee();
}
function swapBack() private lockTheSwap {
uint256 contractBalance = balanceOf(address(this));
bool success;
uint256 totalTokensToSwap = _liquidityTokensToSwap + _marketingTokensToSwap;
if(totalTokensToSwap == 0 || contractBalance == 0) {return;}
// Halve the amount of liquidity tokens
uint256 tokensForLiquidity = (contractBalance * _liquidityTokensToSwap / totalTokensToSwap) / 2;
uint256 amountToSwapForBNB = contractBalance.sub(tokensForLiquidity);
uint256 initialBNBBalance = address(this).balance;
swapTokensForBNB(amountToSwapForBNB);
uint256 bnbBalance = address(this).balance.sub(initialBNBBalance);
uint256 bnbForMarketing = bnbBalance.mul(_marketingTokensToSwap).div(totalTokensToSwap);
uint256 bnbForLiquidity = bnbBalance - bnbForMarketing;
_liquidityTokensToSwap = 0;
_marketingTokensToSwap = 0;
if(tokensForLiquidity > 0 && bnbForLiquidity > 0){
addLiquidity(tokensForLiquidity, bnbForLiquidity);
emit SwapAndLiquify(amountToSwapForBNB, bnbForLiquidity, tokensForLiquidity);
}
(success,) = address(marketingAddress).call{value: address(this).balance}("");
}
function swapTokensForBNB(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
liquidityAddress,
block.timestamp
);
}
function _tokenTransfer(
address sender,
address recipient,
uint256 amount
) private {
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
}
function _transferStandard(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferBothExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
function _getValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256,
uint256,
uint256,
uint256
)
{
(
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(
tAmount,
tFee,
tLiquidity,
_getRate()
);
return (
rAmount,
rTransferAmount,
rFee,
tTransferAmount,
tFee,
tLiquidity
);
}
function _getTValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256
)
{
uint256 tFee = calculateTaxFee(tAmount);
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
return (tTransferAmount, tFee, tLiquidity);
}
function _getRValues(
uint256 tAmount,
uint256 tFee,
uint256 tLiquidity,
uint256 currentRate
)
private
pure
returns (
uint256,
uint256,
uint256
)
{
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rLiquidity = tLiquidity.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns (uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns (uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (
_rOwned[_excluded[i]] > rSupply ||
_tOwned[_excluded[i]] > tSupply
) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _takeLiquidity(uint256 tLiquidity) private {
if(buyOrSellSwitch == BUY){
_liquidityTokensToSwap += tLiquidity * _buyLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _buyMarketingFee / _liquidityFee;
} else if(buyOrSellSwitch == SELL){
_liquidityTokensToSwap += tLiquidity * _sellLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _sellMarketingFee / _liquidityFee;
}
uint256 currentRate = _getRate();
uint256 rLiquidity = tLiquidity.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
if (_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(10**2);
}
function calculateLiquidityFee(uint256 _amount)
private
view
returns (uint256)
{
return _amount.mul(_liquidityFee).div(10**2);
}
function removeAllFee() private {
if (_taxFee == 0 && _liquidityFee == 0) return;
_previousTaxFee = _taxFee;
_previousLiquidityFee = _liquidityFee;
_taxFee = 0;
_liquidityFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_liquidityFee = _previousLiquidityFee;
}
function isExcludedFromFee(address account) external view returns (bool) {
return _isExcludedFromFee[account];
}
function excludeFromFee(address account) external onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) external onlyOwner {
_isExcludedFromFee[account] = false;
}
function setBuyFee(uint256 buyTaxFee, uint256 buyLiquidityFee, uint256 buyMarketingFee)
external
onlyOwner
{
_buyTaxFee = buyTaxFee;
_buyLiquidityFee = buyLiquidityFee;
_buyMarketingFee = buyMarketingFee;
require(_buyTaxFee + _buyLiquidityFee + _buyMarketingFee <= 20, "Must keep taxes below 20%");
}
function setSellFee(uint256 sellTaxFee, uint256 sellLiquidityFee, uint256 sellMarketingFee)
external
onlyOwner
{
_sellTaxFee = sellTaxFee;
_sellLiquidityFee = sellLiquidityFee;
_sellMarketingFee = sellMarketingFee;
require(_sellTaxFee + _sellLiquidityFee + _sellMarketingFee <= 30, "Must keep taxes below 30%");
}
function setMarketingAddress(address _marketingAddress) external onlyOwner {
marketingAddress = payable(_marketingAddress);
_isExcludedFromFee[marketingAddress] = true;
}
function setLiquidityAddress(address _liquidityAddress) external onlyOwner {
liquidityAddress = payable(_liquidityAddress);
_isExcludedFromFee[liquidityAddress] = true;
}
function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
// useful for buybacks or to reclaim any BNB on the contract in a way that helps holders.
function buyBackTokens(uint256 bnbAmountInWei) external onlyOwner {
// generate the uniswap pair path of weth -> eth
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
// make the swap
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: bnbAmountInWei}(
0, // accept any amount of Ethereum
path,
address(0xdead),
block.timestamp
);
}
// To receive ETH from uniswapV2Router when swapping
receive() external payable {}
function transferForeignToken(address _token, address _to)
external
onlyOwner
returns (bool _sent)
{
require(_token != address(this), "Can't withdraw native tokens");
uint256 _contractBalance = IERC20(_token).balanceOf(address(this));
_sent = IERC20(_token).transfer(_to, _contractBalance);
}
} | removeLimits | function removeLimits() external onlyOwner returns (bool){
limitsInEffect = false;
gasLimitActive = false;
transferDelayEnabled = false;
return true;
}
| // remove limits after token is stable - 30-60 minutes | LineComment | v0.8.9+commit.e5eed63a | None | ipfs://ab890a60740e4b9b0482010b3d9ce59818bbb6af2d1c9e9d588b1854bf2f3a6c | {
"func_code_index": [
9961,
10158
]
} | 9,662 |
||
MINIMANEKINEKO | MINIMANEKINEKO.sol | 0x48749b6b81ec168b27f94baa66a5df0e65855382 | Solidity | MINIMANEKINEKO | contract MINIMANEKINEKO is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
address payable public marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // Marketing Address
address payable public liquidityAddress =
payable(0x000000000000000000000000000000000000dEaD); // Liquidity Address
mapping(address => uint256) private _rOwned;
mapping(address => uint256) private _tOwned;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isExcludedFromFee;
mapping(address => bool) private _isExcluded;
address[] private _excluded;
uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 100 * 1e9 * 1e18;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
string private constant _name = "mini-MANEKI-NEKO";
string private constant _symbol = "miniNEKO";
uint8 private constant _decimals = 18;
uint256 private constant BUY = 1;
uint256 private constant SELL = 2;
uint256 private constant TRANSFER = 3;
uint256 private buyOrSellSwitch;
// these values are pretty much arbitrary since they get overwritten for every txn, but the placeholders make it easier to work with current contract.
uint256 private _taxFee;
uint256 private _previousTaxFee = _taxFee;
uint256 private _liquidityFee;
uint256 private _previousLiquidityFee = _liquidityFee;
uint256 public _buyTaxFee = 0;
uint256 public _buyLiquidityFee = 5;
uint256 public _buyMarketingFee = 0;
uint256 public _sellTaxFee = 0;
uint256 public _sellLiquidityFee = 8;
uint256 public _sellMarketingFee = 7;
uint256 public liquidityActiveBlock = 0; // 0 means liquidity is not active yet
uint256 public tradingActiveBlock = 0; // 0 means trading is not active
bool public limitsInEffect = true;
bool public tradingActive = false;
bool public swapEnabled = false;
mapping (address => bool) public _isExcludedMaxTransactionAmount;
// Anti-bot and anti-whale mappings and variables
mapping(address => uint256) private _holderLastTransferTimestamp; // to hold last Transfers temporarily during launch
bool public transferDelayEnabled = true;
uint256 private _liquidityTokensToSwap;
uint256 private _marketingTokensToSwap;
bool private gasLimitActive = true;
uint256 private gasPriceLimit = 602 * 1 gwei;
// store addresses that a automatic market maker pairs. Any transfer *to* these addresses
// could be subject to a maximum transfer amount
mapping (address => bool) public automatedMarketMakerPairs;
uint256 public minimumTokensBeforeSwap;
uint256 public maxTransactionAmount;
uint256 public maxWallet;
IUniswapV2Router02 public uniswapV2Router;
address public uniswapV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = false;
event RewardLiquidityProviders(uint256 tokenAmount);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
event SwapETHForTokens(uint256 amountIn, address[] path);
event SwapTokensForETH(uint256 amountIn, address[] path);
event ExcludedMaxTransactionAmount(address indexed account, bool isExcluded);
modifier lockTheSwap() {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor() {
address newOwner = msg.sender; // update if auto-deploying to a different wallet
address futureOwner = address(msg.sender); // use if ownership will be transferred after deployment.
maxTransactionAmount = _tTotal * 3 / 1000; // 0.3% max txn
minimumTokensBeforeSwap = _tTotal * 3 / 10000; // 0.03%
maxWallet = _tTotal * 3 / 1000; // .3%
_rOwned[newOwner] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(
// ROPSTEN or HARDHAT
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
);
address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;
uniswapV2Pair = _uniswapV2Pair;
marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // update to marketing address
liquidityAddress = payable(address(0xdead)); // update to a liquidity wallet if you don't want to burn LP tokens generated by the contract.
_setAutomatedMarketMakerPair(_uniswapV2Pair, true);
_isExcludedFromFee[newOwner] = true;
_isExcludedFromFee[futureOwner] = true; // pre-exclude future owner wallet
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[liquidityAddress] = true;
excludeFromMaxTransaction(newOwner, true);
excludeFromMaxTransaction(futureOwner, true); // pre-exclude future owner wallet
excludeFromMaxTransaction(address(this), true);
excludeFromMaxTransaction(address(_uniswapV2Router), true);
excludeFromMaxTransaction(address(0xdead), true);
emit Transfer(address(0), newOwner, _tTotal);
}
function name() external pure returns (string memory) {
return _name;
}
function symbol() external pure returns (string memory) {
return _symbol;
}
function decimals() external pure returns (uint8) {
return _decimals;
}
function totalSupply() external pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount)
external
override
returns (bool)
{
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender)
external
view
override
returns (uint256)
{
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount)
public
override
returns (bool)
{
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()].sub(
amount,
"ERC20: transfer amount exceeds allowance"
)
);
return true;
}
function increaseAllowance(address spender, uint256 addedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].add(addedValue)
);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].sub(
subtractedValue,
"ERC20: decreased allowance below zero"
)
);
return true;
}
function isExcludedFromReward(address account)
external
view
returns (bool)
{
return _isExcluded[account];
}
function totalFees() external view returns (uint256) {
return _tFeeTotal;
}
// once enabled, can never be turned off
function enableTrading() external onlyOwner {
tradingActive = true;
swapAndLiquifyEnabled = true;
tradingActiveBlock = block.number;
}
function minimumTokensBeforeSwapAmount() external view returns (uint256) {
return minimumTokensBeforeSwap;
}
function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner {
require(pair != uniswapV2Pair, "The pair cannot be removed from automatedMarketMakerPairs");
_setAutomatedMarketMakerPair(pair, value);
}
function _setAutomatedMarketMakerPair(address pair, bool value) private {
automatedMarketMakerPairs[pair] = value;
excludeFromMaxTransaction(pair, value);
if(value){excludeFromReward(pair);}
if(!value){includeInReward(pair);}
}
function setProtectionSettings(bool antiGas) external onlyOwner() {
gasLimitActive = antiGas;
}
function setGasPriceLimit(uint256 gas) external onlyOwner {
require(gas >= 300);
gasPriceLimit = gas * 1 gwei;
}
// disable Transfer delay
function disableTransferDelay() external onlyOwner returns (bool){
transferDelayEnabled = false;
return true;
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee)
external
view
returns (uint256)
{
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount, , , , , ) = _getValues(tAmount);
return rAmount;
} else {
(, uint256 rTransferAmount, , , , ) = _getValues(tAmount);
return rTransferAmount;
}
}
// remove limits after token is stable - 30-60 minutes
function removeLimits() external onlyOwner returns (bool){
limitsInEffect = false;
gasLimitActive = false;
transferDelayEnabled = false;
return true;
}
function tokenFromReflection(uint256 rAmount)
public
view
returns (uint256)
{
require(
rAmount <= _rTotal,
"Amount must be less than total reflections"
);
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeFromReward(address account) public onlyOwner {
require(!_isExcluded[account], "Account is already excluded");
require(_excluded.length + 1 <= 50, "Cannot exclude more than 50 accounts. Include a previously excluded address.");
if (_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function excludeFromMaxTransaction(address updAds, bool isEx) public onlyOwner {
_isExcludedMaxTransactionAmount[updAds] = isEx;
emit ExcludedMaxTransactionAmount(updAds, isEx);
}
function includeInReward(address account) public onlyOwner {
require(_isExcluded[account], "Account is not excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function _approve(
address owner,
address spender,
uint256 amount
) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(
address from,
address to,
uint256 amount
) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(!tradingActive){
require(_isExcludedFromFee[from] || _isExcludedFromFee[to], "Trading is not active yet.");
}
if(limitsInEffect){
if (
from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead) &&
!inSwapAndLiquify
){
// only use to prevent sniper buys in the first blocks.
if (gasLimitActive && automatedMarketMakerPairs[from]) {
require(tx.gasprice <= gasPriceLimit, "Gas price exceeds limit.");
}
// at launch if the transfer delay is enabled, ensure the block timestamps for purchasers is set -- during launch.
if (transferDelayEnabled){
if (to != owner() && to != address(uniswapV2Router) && to != address(uniswapV2Pair)){
require(_holderLastTransferTimestamp[tx.origin] < block.number, "_transfer:: Transfer Delay enabled. Only one purchase per block allowed.");
_holderLastTransferTimestamp[tx.origin] = block.number;
}
}
//when buy
if (automatedMarketMakerPairs[from] && !_isExcludedMaxTransactionAmount[to]) {
require(amount <= maxTransactionAmount, "Buy transfer amount exceeds the maxTransactionAmount.");
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
//when sell
else if (automatedMarketMakerPairs[to] && !_isExcludedMaxTransactionAmount[from]) {
require(amount <= maxTransactionAmount, "Sell transfer amount exceeds the maxTransactionAmount.");
}
else if (!_isExcludedMaxTransactionAmount[to]){
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
}
}
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinimumTokenBalance = contractTokenBalance >=
minimumTokensBeforeSwap;
// Sell tokens for ETH
if (
!inSwapAndLiquify &&
swapAndLiquifyEnabled &&
balanceOf(uniswapV2Pair) > 0 &&
overMinimumTokenBalance &&
automatedMarketMakerPairs[to]
) {
swapBack();
}
removeAllFee();
buyOrSellSwitch = TRANSFER;
// If any account belongs to _isExcludedFromFee account then remove the fee
if (!_isExcludedFromFee[from] && !_isExcludedFromFee[to]) {
// Buy
if (automatedMarketMakerPairs[from]) {
_taxFee = _buyTaxFee;
_liquidityFee = _buyLiquidityFee + _buyMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = BUY;
}
}
// Sell
else if (automatedMarketMakerPairs[to]) {
_taxFee = _sellTaxFee;
_liquidityFee = _sellLiquidityFee + _sellMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = SELL;
}
}
}
_tokenTransfer(from, to, amount);
restoreAllFee();
}
function swapBack() private lockTheSwap {
uint256 contractBalance = balanceOf(address(this));
bool success;
uint256 totalTokensToSwap = _liquidityTokensToSwap + _marketingTokensToSwap;
if(totalTokensToSwap == 0 || contractBalance == 0) {return;}
// Halve the amount of liquidity tokens
uint256 tokensForLiquidity = (contractBalance * _liquidityTokensToSwap / totalTokensToSwap) / 2;
uint256 amountToSwapForBNB = contractBalance.sub(tokensForLiquidity);
uint256 initialBNBBalance = address(this).balance;
swapTokensForBNB(amountToSwapForBNB);
uint256 bnbBalance = address(this).balance.sub(initialBNBBalance);
uint256 bnbForMarketing = bnbBalance.mul(_marketingTokensToSwap).div(totalTokensToSwap);
uint256 bnbForLiquidity = bnbBalance - bnbForMarketing;
_liquidityTokensToSwap = 0;
_marketingTokensToSwap = 0;
if(tokensForLiquidity > 0 && bnbForLiquidity > 0){
addLiquidity(tokensForLiquidity, bnbForLiquidity);
emit SwapAndLiquify(amountToSwapForBNB, bnbForLiquidity, tokensForLiquidity);
}
(success,) = address(marketingAddress).call{value: address(this).balance}("");
}
function swapTokensForBNB(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
liquidityAddress,
block.timestamp
);
}
function _tokenTransfer(
address sender,
address recipient,
uint256 amount
) private {
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
}
function _transferStandard(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferBothExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
function _getValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256,
uint256,
uint256,
uint256
)
{
(
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(
tAmount,
tFee,
tLiquidity,
_getRate()
);
return (
rAmount,
rTransferAmount,
rFee,
tTransferAmount,
tFee,
tLiquidity
);
}
function _getTValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256
)
{
uint256 tFee = calculateTaxFee(tAmount);
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
return (tTransferAmount, tFee, tLiquidity);
}
function _getRValues(
uint256 tAmount,
uint256 tFee,
uint256 tLiquidity,
uint256 currentRate
)
private
pure
returns (
uint256,
uint256,
uint256
)
{
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rLiquidity = tLiquidity.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns (uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns (uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (
_rOwned[_excluded[i]] > rSupply ||
_tOwned[_excluded[i]] > tSupply
) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _takeLiquidity(uint256 tLiquidity) private {
if(buyOrSellSwitch == BUY){
_liquidityTokensToSwap += tLiquidity * _buyLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _buyMarketingFee / _liquidityFee;
} else if(buyOrSellSwitch == SELL){
_liquidityTokensToSwap += tLiquidity * _sellLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _sellMarketingFee / _liquidityFee;
}
uint256 currentRate = _getRate();
uint256 rLiquidity = tLiquidity.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
if (_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(10**2);
}
function calculateLiquidityFee(uint256 _amount)
private
view
returns (uint256)
{
return _amount.mul(_liquidityFee).div(10**2);
}
function removeAllFee() private {
if (_taxFee == 0 && _liquidityFee == 0) return;
_previousTaxFee = _taxFee;
_previousLiquidityFee = _liquidityFee;
_taxFee = 0;
_liquidityFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_liquidityFee = _previousLiquidityFee;
}
function isExcludedFromFee(address account) external view returns (bool) {
return _isExcludedFromFee[account];
}
function excludeFromFee(address account) external onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) external onlyOwner {
_isExcludedFromFee[account] = false;
}
function setBuyFee(uint256 buyTaxFee, uint256 buyLiquidityFee, uint256 buyMarketingFee)
external
onlyOwner
{
_buyTaxFee = buyTaxFee;
_buyLiquidityFee = buyLiquidityFee;
_buyMarketingFee = buyMarketingFee;
require(_buyTaxFee + _buyLiquidityFee + _buyMarketingFee <= 20, "Must keep taxes below 20%");
}
function setSellFee(uint256 sellTaxFee, uint256 sellLiquidityFee, uint256 sellMarketingFee)
external
onlyOwner
{
_sellTaxFee = sellTaxFee;
_sellLiquidityFee = sellLiquidityFee;
_sellMarketingFee = sellMarketingFee;
require(_sellTaxFee + _sellLiquidityFee + _sellMarketingFee <= 30, "Must keep taxes below 30%");
}
function setMarketingAddress(address _marketingAddress) external onlyOwner {
marketingAddress = payable(_marketingAddress);
_isExcludedFromFee[marketingAddress] = true;
}
function setLiquidityAddress(address _liquidityAddress) external onlyOwner {
liquidityAddress = payable(_liquidityAddress);
_isExcludedFromFee[liquidityAddress] = true;
}
function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
// useful for buybacks or to reclaim any BNB on the contract in a way that helps holders.
function buyBackTokens(uint256 bnbAmountInWei) external onlyOwner {
// generate the uniswap pair path of weth -> eth
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
// make the swap
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: bnbAmountInWei}(
0, // accept any amount of Ethereum
path,
address(0xdead),
block.timestamp
);
}
// To receive ETH from uniswapV2Router when swapping
receive() external payable {}
function transferForeignToken(address _token, address _to)
external
onlyOwner
returns (bool _sent)
{
require(_token != address(this), "Can't withdraw native tokens");
uint256 _contractBalance = IERC20(_token).balanceOf(address(this));
_sent = IERC20(_token).transfer(_to, _contractBalance);
}
} | buyBackTokens | function buyBackTokens(uint256 bnbAmountInWei) external onlyOwner {
// generate the uniswap pair path of weth -> eth
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
// make the swap
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: bnbAmountInWei}(
0, // accept any amount of Ethereum
path,
address(0xdead),
block.timestamp
);
}
| // useful for buybacks or to reclaim any BNB on the contract in a way that helps holders. | LineComment | v0.8.9+commit.e5eed63a | None | ipfs://ab890a60740e4b9b0482010b3d9ce59818bbb6af2d1c9e9d588b1854bf2f3a6c | {
"func_code_index": [
27424,
27956
]
} | 9,663 |
||
MINIMANEKINEKO | MINIMANEKINEKO.sol | 0x48749b6b81ec168b27f94baa66a5df0e65855382 | Solidity | MINIMANEKINEKO | contract MINIMANEKINEKO is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
address payable public marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // Marketing Address
address payable public liquidityAddress =
payable(0x000000000000000000000000000000000000dEaD); // Liquidity Address
mapping(address => uint256) private _rOwned;
mapping(address => uint256) private _tOwned;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isExcludedFromFee;
mapping(address => bool) private _isExcluded;
address[] private _excluded;
uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 100 * 1e9 * 1e18;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
string private constant _name = "mini-MANEKI-NEKO";
string private constant _symbol = "miniNEKO";
uint8 private constant _decimals = 18;
uint256 private constant BUY = 1;
uint256 private constant SELL = 2;
uint256 private constant TRANSFER = 3;
uint256 private buyOrSellSwitch;
// these values are pretty much arbitrary since they get overwritten for every txn, but the placeholders make it easier to work with current contract.
uint256 private _taxFee;
uint256 private _previousTaxFee = _taxFee;
uint256 private _liquidityFee;
uint256 private _previousLiquidityFee = _liquidityFee;
uint256 public _buyTaxFee = 0;
uint256 public _buyLiquidityFee = 5;
uint256 public _buyMarketingFee = 0;
uint256 public _sellTaxFee = 0;
uint256 public _sellLiquidityFee = 8;
uint256 public _sellMarketingFee = 7;
uint256 public liquidityActiveBlock = 0; // 0 means liquidity is not active yet
uint256 public tradingActiveBlock = 0; // 0 means trading is not active
bool public limitsInEffect = true;
bool public tradingActive = false;
bool public swapEnabled = false;
mapping (address => bool) public _isExcludedMaxTransactionAmount;
// Anti-bot and anti-whale mappings and variables
mapping(address => uint256) private _holderLastTransferTimestamp; // to hold last Transfers temporarily during launch
bool public transferDelayEnabled = true;
uint256 private _liquidityTokensToSwap;
uint256 private _marketingTokensToSwap;
bool private gasLimitActive = true;
uint256 private gasPriceLimit = 602 * 1 gwei;
// store addresses that a automatic market maker pairs. Any transfer *to* these addresses
// could be subject to a maximum transfer amount
mapping (address => bool) public automatedMarketMakerPairs;
uint256 public minimumTokensBeforeSwap;
uint256 public maxTransactionAmount;
uint256 public maxWallet;
IUniswapV2Router02 public uniswapV2Router;
address public uniswapV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = false;
event RewardLiquidityProviders(uint256 tokenAmount);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
event SwapETHForTokens(uint256 amountIn, address[] path);
event SwapTokensForETH(uint256 amountIn, address[] path);
event ExcludedMaxTransactionAmount(address indexed account, bool isExcluded);
modifier lockTheSwap() {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor() {
address newOwner = msg.sender; // update if auto-deploying to a different wallet
address futureOwner = address(msg.sender); // use if ownership will be transferred after deployment.
maxTransactionAmount = _tTotal * 3 / 1000; // 0.3% max txn
minimumTokensBeforeSwap = _tTotal * 3 / 10000; // 0.03%
maxWallet = _tTotal * 3 / 1000; // .3%
_rOwned[newOwner] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(
// ROPSTEN or HARDHAT
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
);
address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;
uniswapV2Pair = _uniswapV2Pair;
marketingAddress = payable(0x8E2155B902350b44673E4d10142fa86fa9fDbF7f); // update to marketing address
liquidityAddress = payable(address(0xdead)); // update to a liquidity wallet if you don't want to burn LP tokens generated by the contract.
_setAutomatedMarketMakerPair(_uniswapV2Pair, true);
_isExcludedFromFee[newOwner] = true;
_isExcludedFromFee[futureOwner] = true; // pre-exclude future owner wallet
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[liquidityAddress] = true;
excludeFromMaxTransaction(newOwner, true);
excludeFromMaxTransaction(futureOwner, true); // pre-exclude future owner wallet
excludeFromMaxTransaction(address(this), true);
excludeFromMaxTransaction(address(_uniswapV2Router), true);
excludeFromMaxTransaction(address(0xdead), true);
emit Transfer(address(0), newOwner, _tTotal);
}
function name() external pure returns (string memory) {
return _name;
}
function symbol() external pure returns (string memory) {
return _symbol;
}
function decimals() external pure returns (uint8) {
return _decimals;
}
function totalSupply() external pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount)
external
override
returns (bool)
{
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender)
external
view
override
returns (uint256)
{
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount)
public
override
returns (bool)
{
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()].sub(
amount,
"ERC20: transfer amount exceeds allowance"
)
);
return true;
}
function increaseAllowance(address spender, uint256 addedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].add(addedValue)
);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue)
external
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].sub(
subtractedValue,
"ERC20: decreased allowance below zero"
)
);
return true;
}
function isExcludedFromReward(address account)
external
view
returns (bool)
{
return _isExcluded[account];
}
function totalFees() external view returns (uint256) {
return _tFeeTotal;
}
// once enabled, can never be turned off
function enableTrading() external onlyOwner {
tradingActive = true;
swapAndLiquifyEnabled = true;
tradingActiveBlock = block.number;
}
function minimumTokensBeforeSwapAmount() external view returns (uint256) {
return minimumTokensBeforeSwap;
}
function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner {
require(pair != uniswapV2Pair, "The pair cannot be removed from automatedMarketMakerPairs");
_setAutomatedMarketMakerPair(pair, value);
}
function _setAutomatedMarketMakerPair(address pair, bool value) private {
automatedMarketMakerPairs[pair] = value;
excludeFromMaxTransaction(pair, value);
if(value){excludeFromReward(pair);}
if(!value){includeInReward(pair);}
}
function setProtectionSettings(bool antiGas) external onlyOwner() {
gasLimitActive = antiGas;
}
function setGasPriceLimit(uint256 gas) external onlyOwner {
require(gas >= 300);
gasPriceLimit = gas * 1 gwei;
}
// disable Transfer delay
function disableTransferDelay() external onlyOwner returns (bool){
transferDelayEnabled = false;
return true;
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee)
external
view
returns (uint256)
{
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount, , , , , ) = _getValues(tAmount);
return rAmount;
} else {
(, uint256 rTransferAmount, , , , ) = _getValues(tAmount);
return rTransferAmount;
}
}
// remove limits after token is stable - 30-60 minutes
function removeLimits() external onlyOwner returns (bool){
limitsInEffect = false;
gasLimitActive = false;
transferDelayEnabled = false;
return true;
}
function tokenFromReflection(uint256 rAmount)
public
view
returns (uint256)
{
require(
rAmount <= _rTotal,
"Amount must be less than total reflections"
);
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeFromReward(address account) public onlyOwner {
require(!_isExcluded[account], "Account is already excluded");
require(_excluded.length + 1 <= 50, "Cannot exclude more than 50 accounts. Include a previously excluded address.");
if (_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function excludeFromMaxTransaction(address updAds, bool isEx) public onlyOwner {
_isExcludedMaxTransactionAmount[updAds] = isEx;
emit ExcludedMaxTransactionAmount(updAds, isEx);
}
function includeInReward(address account) public onlyOwner {
require(_isExcluded[account], "Account is not excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function _approve(
address owner,
address spender,
uint256 amount
) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(
address from,
address to,
uint256 amount
) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(!tradingActive){
require(_isExcludedFromFee[from] || _isExcludedFromFee[to], "Trading is not active yet.");
}
if(limitsInEffect){
if (
from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead) &&
!inSwapAndLiquify
){
// only use to prevent sniper buys in the first blocks.
if (gasLimitActive && automatedMarketMakerPairs[from]) {
require(tx.gasprice <= gasPriceLimit, "Gas price exceeds limit.");
}
// at launch if the transfer delay is enabled, ensure the block timestamps for purchasers is set -- during launch.
if (transferDelayEnabled){
if (to != owner() && to != address(uniswapV2Router) && to != address(uniswapV2Pair)){
require(_holderLastTransferTimestamp[tx.origin] < block.number, "_transfer:: Transfer Delay enabled. Only one purchase per block allowed.");
_holderLastTransferTimestamp[tx.origin] = block.number;
}
}
//when buy
if (automatedMarketMakerPairs[from] && !_isExcludedMaxTransactionAmount[to]) {
require(amount <= maxTransactionAmount, "Buy transfer amount exceeds the maxTransactionAmount.");
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
//when sell
else if (automatedMarketMakerPairs[to] && !_isExcludedMaxTransactionAmount[from]) {
require(amount <= maxTransactionAmount, "Sell transfer amount exceeds the maxTransactionAmount.");
}
else if (!_isExcludedMaxTransactionAmount[to]){
require(amount + balanceOf(to) <= maxWallet, "Cannot exceed max wallet");
}
}
}
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinimumTokenBalance = contractTokenBalance >=
minimumTokensBeforeSwap;
// Sell tokens for ETH
if (
!inSwapAndLiquify &&
swapAndLiquifyEnabled &&
balanceOf(uniswapV2Pair) > 0 &&
overMinimumTokenBalance &&
automatedMarketMakerPairs[to]
) {
swapBack();
}
removeAllFee();
buyOrSellSwitch = TRANSFER;
// If any account belongs to _isExcludedFromFee account then remove the fee
if (!_isExcludedFromFee[from] && !_isExcludedFromFee[to]) {
// Buy
if (automatedMarketMakerPairs[from]) {
_taxFee = _buyTaxFee;
_liquidityFee = _buyLiquidityFee + _buyMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = BUY;
}
}
// Sell
else if (automatedMarketMakerPairs[to]) {
_taxFee = _sellTaxFee;
_liquidityFee = _sellLiquidityFee + _sellMarketingFee;
if(_liquidityFee > 0){
buyOrSellSwitch = SELL;
}
}
}
_tokenTransfer(from, to, amount);
restoreAllFee();
}
function swapBack() private lockTheSwap {
uint256 contractBalance = balanceOf(address(this));
bool success;
uint256 totalTokensToSwap = _liquidityTokensToSwap + _marketingTokensToSwap;
if(totalTokensToSwap == 0 || contractBalance == 0) {return;}
// Halve the amount of liquidity tokens
uint256 tokensForLiquidity = (contractBalance * _liquidityTokensToSwap / totalTokensToSwap) / 2;
uint256 amountToSwapForBNB = contractBalance.sub(tokensForLiquidity);
uint256 initialBNBBalance = address(this).balance;
swapTokensForBNB(amountToSwapForBNB);
uint256 bnbBalance = address(this).balance.sub(initialBNBBalance);
uint256 bnbForMarketing = bnbBalance.mul(_marketingTokensToSwap).div(totalTokensToSwap);
uint256 bnbForLiquidity = bnbBalance - bnbForMarketing;
_liquidityTokensToSwap = 0;
_marketingTokensToSwap = 0;
if(tokensForLiquidity > 0 && bnbForLiquidity > 0){
addLiquidity(tokensForLiquidity, bnbForLiquidity);
emit SwapAndLiquify(amountToSwapForBNB, bnbForLiquidity, tokensForLiquidity);
}
(success,) = address(marketingAddress).call{value: address(this).balance}("");
}
function swapTokensForBNB(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
liquidityAddress,
block.timestamp
);
}
function _tokenTransfer(
address sender,
address recipient,
uint256 amount
) private {
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
}
function _transferStandard(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferBothExcluded(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
function _getValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256,
uint256,
uint256,
uint256
)
{
(
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(
tAmount,
tFee,
tLiquidity,
_getRate()
);
return (
rAmount,
rTransferAmount,
rFee,
tTransferAmount,
tFee,
tLiquidity
);
}
function _getTValues(uint256 tAmount)
private
view
returns (
uint256,
uint256,
uint256
)
{
uint256 tFee = calculateTaxFee(tAmount);
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
return (tTransferAmount, tFee, tLiquidity);
}
function _getRValues(
uint256 tAmount,
uint256 tFee,
uint256 tLiquidity,
uint256 currentRate
)
private
pure
returns (
uint256,
uint256,
uint256
)
{
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rLiquidity = tLiquidity.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns (uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns (uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (
_rOwned[_excluded[i]] > rSupply ||
_tOwned[_excluded[i]] > tSupply
) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _takeLiquidity(uint256 tLiquidity) private {
if(buyOrSellSwitch == BUY){
_liquidityTokensToSwap += tLiquidity * _buyLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _buyMarketingFee / _liquidityFee;
} else if(buyOrSellSwitch == SELL){
_liquidityTokensToSwap += tLiquidity * _sellLiquidityFee / _liquidityFee;
_marketingTokensToSwap += tLiquidity * _sellMarketingFee / _liquidityFee;
}
uint256 currentRate = _getRate();
uint256 rLiquidity = tLiquidity.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
if (_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(10**2);
}
function calculateLiquidityFee(uint256 _amount)
private
view
returns (uint256)
{
return _amount.mul(_liquidityFee).div(10**2);
}
function removeAllFee() private {
if (_taxFee == 0 && _liquidityFee == 0) return;
_previousTaxFee = _taxFee;
_previousLiquidityFee = _liquidityFee;
_taxFee = 0;
_liquidityFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_liquidityFee = _previousLiquidityFee;
}
function isExcludedFromFee(address account) external view returns (bool) {
return _isExcludedFromFee[account];
}
function excludeFromFee(address account) external onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) external onlyOwner {
_isExcludedFromFee[account] = false;
}
function setBuyFee(uint256 buyTaxFee, uint256 buyLiquidityFee, uint256 buyMarketingFee)
external
onlyOwner
{
_buyTaxFee = buyTaxFee;
_buyLiquidityFee = buyLiquidityFee;
_buyMarketingFee = buyMarketingFee;
require(_buyTaxFee + _buyLiquidityFee + _buyMarketingFee <= 20, "Must keep taxes below 20%");
}
function setSellFee(uint256 sellTaxFee, uint256 sellLiquidityFee, uint256 sellMarketingFee)
external
onlyOwner
{
_sellTaxFee = sellTaxFee;
_sellLiquidityFee = sellLiquidityFee;
_sellMarketingFee = sellMarketingFee;
require(_sellTaxFee + _sellLiquidityFee + _sellMarketingFee <= 30, "Must keep taxes below 30%");
}
function setMarketingAddress(address _marketingAddress) external onlyOwner {
marketingAddress = payable(_marketingAddress);
_isExcludedFromFee[marketingAddress] = true;
}
function setLiquidityAddress(address _liquidityAddress) external onlyOwner {
liquidityAddress = payable(_liquidityAddress);
_isExcludedFromFee[liquidityAddress] = true;
}
function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
// useful for buybacks or to reclaim any BNB on the contract in a way that helps holders.
function buyBackTokens(uint256 bnbAmountInWei) external onlyOwner {
// generate the uniswap pair path of weth -> eth
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
// make the swap
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: bnbAmountInWei}(
0, // accept any amount of Ethereum
path,
address(0xdead),
block.timestamp
);
}
// To receive ETH from uniswapV2Router when swapping
receive() external payable {}
function transferForeignToken(address _token, address _to)
external
onlyOwner
returns (bool _sent)
{
require(_token != address(this), "Can't withdraw native tokens");
uint256 _contractBalance = IERC20(_token).balanceOf(address(this));
_sent = IERC20(_token).transfer(_to, _contractBalance);
}
} | // To receive ETH from uniswapV2Router when swapping | LineComment | v0.8.9+commit.e5eed63a | None | ipfs://ab890a60740e4b9b0482010b3d9ce59818bbb6af2d1c9e9d588b1854bf2f3a6c | {
"func_code_index": [
28017,
28051
]
} | 9,664 |
||||
NJswapToken | contracts/NJswapToken.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | NJswapToken | contract NJswapToken is ERC20("NJswap.org", "NJS"), Ownable {
using SafeMath for uint256;
uint8 public taxRatio = 3;
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(msg.sender, taxAmount);
return super.transfer(recipient, amount.sub(taxAmount));
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(sender, taxAmount);
return super.transferFrom(sender, recipient, amount.sub(taxAmount));
}
/**
* @dev Chef distributes newly generated NJswapToken to each farmmers
* "onlyOwner" :: for the one who worries about the function, this distribute process is only done by MasterChef contract for farming process
*/
function distribute(address _to, uint256 _amount) public onlyOwner {
_distribute(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
/**
* @dev Burning token
*/
function burn(address _from, uint256 _amount) public {
_burn(_from, _amount);
}
/**
* @dev Tokenomic decition from governance
*/
function changeTaxRatio(uint8 _taxRatio) public onlyOwner {
taxRatio = _taxRatio;
}
mapping (address => address) internal _delegates;
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "NJswap.org::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "NJswap.org::delegateBySig: invalid nonce");
require(now <= expiry, "NJswap.org::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "NJswap.org::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "NJswap.org::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | distribute | function distribute(address _to, uint256 _amount) public onlyOwner {
_distribute(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
| /**
* @dev Chef distributes newly generated NJswapToken to each farmmers
* "onlyOwner" :: for the one who worries about the function, this distribute process is only done by MasterChef contract for farming process
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
945,
1124
]
} | 9,665 |
||
NJswapToken | contracts/NJswapToken.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | NJswapToken | contract NJswapToken is ERC20("NJswap.org", "NJS"), Ownable {
using SafeMath for uint256;
uint8 public taxRatio = 3;
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(msg.sender, taxAmount);
return super.transfer(recipient, amount.sub(taxAmount));
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(sender, taxAmount);
return super.transferFrom(sender, recipient, amount.sub(taxAmount));
}
/**
* @dev Chef distributes newly generated NJswapToken to each farmmers
* "onlyOwner" :: for the one who worries about the function, this distribute process is only done by MasterChef contract for farming process
*/
function distribute(address _to, uint256 _amount) public onlyOwner {
_distribute(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
/**
* @dev Burning token
*/
function burn(address _from, uint256 _amount) public {
_burn(_from, _amount);
}
/**
* @dev Tokenomic decition from governance
*/
function changeTaxRatio(uint8 _taxRatio) public onlyOwner {
taxRatio = _taxRatio;
}
mapping (address => address) internal _delegates;
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "NJswap.org::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "NJswap.org::delegateBySig: invalid nonce");
require(now <= expiry, "NJswap.org::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "NJswap.org::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "NJswap.org::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | burn | function burn(address _from, uint256 _amount) public {
_burn(_from, _amount);
}
| /**
* @dev Burning token
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
1176,
1274
]
} | 9,666 |
||
NJswapToken | contracts/NJswapToken.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | NJswapToken | contract NJswapToken is ERC20("NJswap.org", "NJS"), Ownable {
using SafeMath for uint256;
uint8 public taxRatio = 3;
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(msg.sender, taxAmount);
return super.transfer(recipient, amount.sub(taxAmount));
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(sender, taxAmount);
return super.transferFrom(sender, recipient, amount.sub(taxAmount));
}
/**
* @dev Chef distributes newly generated NJswapToken to each farmmers
* "onlyOwner" :: for the one who worries about the function, this distribute process is only done by MasterChef contract for farming process
*/
function distribute(address _to, uint256 _amount) public onlyOwner {
_distribute(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
/**
* @dev Burning token
*/
function burn(address _from, uint256 _amount) public {
_burn(_from, _amount);
}
/**
* @dev Tokenomic decition from governance
*/
function changeTaxRatio(uint8 _taxRatio) public onlyOwner {
taxRatio = _taxRatio;
}
mapping (address => address) internal _delegates;
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "NJswap.org::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "NJswap.org::delegateBySig: invalid nonce");
require(now <= expiry, "NJswap.org::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "NJswap.org::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "NJswap.org::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | changeTaxRatio | function changeTaxRatio(uint8 _taxRatio) public onlyOwner {
taxRatio = _taxRatio;
}
| /**
* @dev Tokenomic decition from governance
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
1347,
1449
]
} | 9,667 |
||
NJswapToken | contracts/NJswapToken.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | NJswapToken | contract NJswapToken is ERC20("NJswap.org", "NJS"), Ownable {
using SafeMath for uint256;
uint8 public taxRatio = 3;
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(msg.sender, taxAmount);
return super.transfer(recipient, amount.sub(taxAmount));
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(sender, taxAmount);
return super.transferFrom(sender, recipient, amount.sub(taxAmount));
}
/**
* @dev Chef distributes newly generated NJswapToken to each farmmers
* "onlyOwner" :: for the one who worries about the function, this distribute process is only done by MasterChef contract for farming process
*/
function distribute(address _to, uint256 _amount) public onlyOwner {
_distribute(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
/**
* @dev Burning token
*/
function burn(address _from, uint256 _amount) public {
_burn(_from, _amount);
}
/**
* @dev Tokenomic decition from governance
*/
function changeTaxRatio(uint8 _taxRatio) public onlyOwner {
taxRatio = _taxRatio;
}
mapping (address => address) internal _delegates;
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "NJswap.org::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "NJswap.org::delegateBySig: invalid nonce");
require(now <= expiry, "NJswap.org::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "NJswap.org::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "NJswap.org::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | delegates | function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
| /**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
2904,
3058
]
} | 9,668 |
||
NJswapToken | contracts/NJswapToken.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | NJswapToken | contract NJswapToken is ERC20("NJswap.org", "NJS"), Ownable {
using SafeMath for uint256;
uint8 public taxRatio = 3;
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(msg.sender, taxAmount);
return super.transfer(recipient, amount.sub(taxAmount));
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(sender, taxAmount);
return super.transferFrom(sender, recipient, amount.sub(taxAmount));
}
/**
* @dev Chef distributes newly generated NJswapToken to each farmmers
* "onlyOwner" :: for the one who worries about the function, this distribute process is only done by MasterChef contract for farming process
*/
function distribute(address _to, uint256 _amount) public onlyOwner {
_distribute(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
/**
* @dev Burning token
*/
function burn(address _from, uint256 _amount) public {
_burn(_from, _amount);
}
/**
* @dev Tokenomic decition from governance
*/
function changeTaxRatio(uint8 _taxRatio) public onlyOwner {
taxRatio = _taxRatio;
}
mapping (address => address) internal _delegates;
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "NJswap.org::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "NJswap.org::delegateBySig: invalid nonce");
require(now <= expiry, "NJswap.org::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "NJswap.org::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "NJswap.org::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | delegate | function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
| /**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
3197,
3306
]
} | 9,669 |
||
NJswapToken | contracts/NJswapToken.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | NJswapToken | contract NJswapToken is ERC20("NJswap.org", "NJS"), Ownable {
using SafeMath for uint256;
uint8 public taxRatio = 3;
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(msg.sender, taxAmount);
return super.transfer(recipient, amount.sub(taxAmount));
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(sender, taxAmount);
return super.transferFrom(sender, recipient, amount.sub(taxAmount));
}
/**
* @dev Chef distributes newly generated NJswapToken to each farmmers
* "onlyOwner" :: for the one who worries about the function, this distribute process is only done by MasterChef contract for farming process
*/
function distribute(address _to, uint256 _amount) public onlyOwner {
_distribute(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
/**
* @dev Burning token
*/
function burn(address _from, uint256 _amount) public {
_burn(_from, _amount);
}
/**
* @dev Tokenomic decition from governance
*/
function changeTaxRatio(uint8 _taxRatio) public onlyOwner {
taxRatio = _taxRatio;
}
mapping (address => address) internal _delegates;
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "NJswap.org::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "NJswap.org::delegateBySig: invalid nonce");
require(now <= expiry, "NJswap.org::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "NJswap.org::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "NJswap.org::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | delegateBySig | function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "NJswap.org::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "NJswap.org::delegateBySig: invalid nonce");
require(now <= expiry, "NJswap.org::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
| /**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
3735,
4936
]
} | 9,670 |
||
NJswapToken | contracts/NJswapToken.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | NJswapToken | contract NJswapToken is ERC20("NJswap.org", "NJS"), Ownable {
using SafeMath for uint256;
uint8 public taxRatio = 3;
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(msg.sender, taxAmount);
return super.transfer(recipient, amount.sub(taxAmount));
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(sender, taxAmount);
return super.transferFrom(sender, recipient, amount.sub(taxAmount));
}
/**
* @dev Chef distributes newly generated NJswapToken to each farmmers
* "onlyOwner" :: for the one who worries about the function, this distribute process is only done by MasterChef contract for farming process
*/
function distribute(address _to, uint256 _amount) public onlyOwner {
_distribute(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
/**
* @dev Burning token
*/
function burn(address _from, uint256 _amount) public {
_burn(_from, _amount);
}
/**
* @dev Tokenomic decition from governance
*/
function changeTaxRatio(uint8 _taxRatio) public onlyOwner {
taxRatio = _taxRatio;
}
mapping (address => address) internal _delegates;
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "NJswap.org::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "NJswap.org::delegateBySig: invalid nonce");
require(now <= expiry, "NJswap.org::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "NJswap.org::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "NJswap.org::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | getCurrentVotes | function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
| /**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
5132,
5392
]
} | 9,671 |
||
NJswapToken | contracts/NJswapToken.sol | 0x83729cc4bdbe929e8f7c094e2df306776222b7c2 | Solidity | NJswapToken | contract NJswapToken is ERC20("NJswap.org", "NJS"), Ownable {
using SafeMath for uint256;
uint8 public taxRatio = 3;
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(msg.sender, taxAmount);
return super.transfer(recipient, amount.sub(taxAmount));
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
uint256 taxAmount = amount.mul(taxRatio).div(100);
_burn(sender, taxAmount);
return super.transferFrom(sender, recipient, amount.sub(taxAmount));
}
/**
* @dev Chef distributes newly generated NJswapToken to each farmmers
* "onlyOwner" :: for the one who worries about the function, this distribute process is only done by MasterChef contract for farming process
*/
function distribute(address _to, uint256 _amount) public onlyOwner {
_distribute(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
/**
* @dev Burning token
*/
function burn(address _from, uint256 _amount) public {
_burn(_from, _amount);
}
/**
* @dev Tokenomic decition from governance
*/
function changeTaxRatio(uint8 _taxRatio) public onlyOwner {
taxRatio = _taxRatio;
}
mapping (address => address) internal _delegates;
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "NJswap.org::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "NJswap.org::delegateBySig: invalid nonce");
require(now <= expiry, "NJswap.org::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "NJswap.org::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "NJswap.org::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | getPriorVotes | function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "NJswap.org::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
| /**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://2cc6975f51943b03407c6fe69648b4173d7a615c655618619e62cefa18c6bc7e | {
"func_code_index": [
5818,
6989
]
} | 9,672 |
||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Interest | contract Interest is Math {
// @notice This function provides compounding in seconds
// @param chi Accumulated interest rate over time
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated When the interest rate was last updated
// @param pie Total sum of all amounts accumulating under one interest rate, divided by that rate
// @return The new accumulated rate, as well as the difference between the debt calculated with the old and new accumulated rates.
function compounding(uint chi, uint ratePerSecond, uint lastUpdated, uint pie) public view returns (uint, uint) {
require(block.timestamp >= lastUpdated, "tinlake-math/invalid-timestamp");
require(chi != 0);
// instead of a interestBearingAmount we use a accumulated interest rate index (chi)
uint updatedChi = _chargeInterest(chi ,ratePerSecond, lastUpdated, block.timestamp);
return (updatedChi, safeSub(rmul(updatedChi, pie), rmul(chi, pie)));
}
// @notice This function charge interest on a interestBearingAmount
// @param interestBearingAmount is the interest bearing amount
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated last time the interest has been charged
// @return interestBearingAmount + interest
function chargeInterest(uint interestBearingAmount, uint ratePerSecond, uint lastUpdated) public view returns (uint) {
if (block.timestamp >= lastUpdated) {
interestBearingAmount = _chargeInterest(interestBearingAmount, ratePerSecond, lastUpdated, block.timestamp);
}
return interestBearingAmount;
}
function _chargeInterest(uint interestBearingAmount, uint ratePerSecond, uint lastUpdated, uint current) internal pure returns (uint) {
return rmul(rpow(ratePerSecond, current - lastUpdated, ONE), interestBearingAmount);
}
// convert pie to debt/savings amount
function toAmount(uint chi, uint pie) public pure returns (uint) {
return rmul(pie, chi);
}
// convert debt/savings amount to pie
function toPie(uint chi, uint amount) public pure returns (uint) {
return rdivup(amount, chi);
}
function rpow(uint x, uint n, uint base) public pure returns (uint z) {
assembly {
switch x case 0 {switch n case 0 {z := base} default {z := 0}}
default {
switch mod(n, 2) case 0 { z := base } default { z := x }
let half := div(base, 2) // for rounding.
for { n := div(n, 2) } n { n := div(n,2) } {
let xx := mul(x, x)
if iszero(eq(div(xx, x), x)) { revert(0,0) }
let xxRound := add(xx, half)
if lt(xxRound, xx) { revert(0,0) }
x := div(xxRound, base)
if mod(n,2) {
let zx := mul(z, x)
if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
let zxRound := add(zx, half)
if lt(zxRound, zx) { revert(0,0) }
z := div(zxRound, base)
}
}
}
}
}
} | /* import "./math.sol"; */ | Comment | compounding | function compounding(uint chi, uint ratePerSecond, uint lastUpdated, uint pie) public view returns (uint, uint) {
require(block.timestamp >= lastUpdated, "tinlake-math/invalid-timestamp");
require(chi != 0);
// instead of a interestBearingAmount we use a accumulated interest rate index (chi)
uint updatedChi = _chargeInterest(chi ,ratePerSecond, lastUpdated, block.timestamp);
return (updatedChi, safeSub(rmul(updatedChi, pie), rmul(chi, pie)));
}
| // @notice This function provides compounding in seconds
// @param chi Accumulated interest rate over time
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated When the interest rate was last updated
// @param pie Total sum of all amounts accumulating under one interest rate, divided by that rate
// @return The new accumulated rate, as well as the difference between the debt calculated with the old and new accumulated rates. | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
526,
1022
]
} | 9,673 |
||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Interest | contract Interest is Math {
// @notice This function provides compounding in seconds
// @param chi Accumulated interest rate over time
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated When the interest rate was last updated
// @param pie Total sum of all amounts accumulating under one interest rate, divided by that rate
// @return The new accumulated rate, as well as the difference between the debt calculated with the old and new accumulated rates.
function compounding(uint chi, uint ratePerSecond, uint lastUpdated, uint pie) public view returns (uint, uint) {
require(block.timestamp >= lastUpdated, "tinlake-math/invalid-timestamp");
require(chi != 0);
// instead of a interestBearingAmount we use a accumulated interest rate index (chi)
uint updatedChi = _chargeInterest(chi ,ratePerSecond, lastUpdated, block.timestamp);
return (updatedChi, safeSub(rmul(updatedChi, pie), rmul(chi, pie)));
}
// @notice This function charge interest on a interestBearingAmount
// @param interestBearingAmount is the interest bearing amount
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated last time the interest has been charged
// @return interestBearingAmount + interest
function chargeInterest(uint interestBearingAmount, uint ratePerSecond, uint lastUpdated) public view returns (uint) {
if (block.timestamp >= lastUpdated) {
interestBearingAmount = _chargeInterest(interestBearingAmount, ratePerSecond, lastUpdated, block.timestamp);
}
return interestBearingAmount;
}
function _chargeInterest(uint interestBearingAmount, uint ratePerSecond, uint lastUpdated, uint current) internal pure returns (uint) {
return rmul(rpow(ratePerSecond, current - lastUpdated, ONE), interestBearingAmount);
}
// convert pie to debt/savings amount
function toAmount(uint chi, uint pie) public pure returns (uint) {
return rmul(pie, chi);
}
// convert debt/savings amount to pie
function toPie(uint chi, uint amount) public pure returns (uint) {
return rdivup(amount, chi);
}
function rpow(uint x, uint n, uint base) public pure returns (uint z) {
assembly {
switch x case 0 {switch n case 0 {z := base} default {z := 0}}
default {
switch mod(n, 2) case 0 { z := base } default { z := x }
let half := div(base, 2) // for rounding.
for { n := div(n, 2) } n { n := div(n,2) } {
let xx := mul(x, x)
if iszero(eq(div(xx, x), x)) { revert(0,0) }
let xxRound := add(xx, half)
if lt(xxRound, xx) { revert(0,0) }
x := div(xxRound, base)
if mod(n,2) {
let zx := mul(z, x)
if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
let zxRound := add(zx, half)
if lt(zxRound, zx) { revert(0,0) }
z := div(zxRound, base)
}
}
}
}
}
} | /* import "./math.sol"; */ | Comment | chargeInterest | function chargeInterest(uint interestBearingAmount, uint ratePerSecond, uint lastUpdated) public view returns (uint) {
if (block.timestamp >= lastUpdated) {
interestBearingAmount = _chargeInterest(interestBearingAmount, ratePerSecond, lastUpdated, block.timestamp);
}
return interestBearingAmount;
}
| // @notice This function charge interest on a interestBearingAmount
// @param interestBearingAmount is the interest bearing amount
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated last time the interest has been charged
// @return interestBearingAmount + interest | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
1357,
1700
]
} | 9,674 |
||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Interest | contract Interest is Math {
// @notice This function provides compounding in seconds
// @param chi Accumulated interest rate over time
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated When the interest rate was last updated
// @param pie Total sum of all amounts accumulating under one interest rate, divided by that rate
// @return The new accumulated rate, as well as the difference between the debt calculated with the old and new accumulated rates.
function compounding(uint chi, uint ratePerSecond, uint lastUpdated, uint pie) public view returns (uint, uint) {
require(block.timestamp >= lastUpdated, "tinlake-math/invalid-timestamp");
require(chi != 0);
// instead of a interestBearingAmount we use a accumulated interest rate index (chi)
uint updatedChi = _chargeInterest(chi ,ratePerSecond, lastUpdated, block.timestamp);
return (updatedChi, safeSub(rmul(updatedChi, pie), rmul(chi, pie)));
}
// @notice This function charge interest on a interestBearingAmount
// @param interestBearingAmount is the interest bearing amount
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated last time the interest has been charged
// @return interestBearingAmount + interest
function chargeInterest(uint interestBearingAmount, uint ratePerSecond, uint lastUpdated) public view returns (uint) {
if (block.timestamp >= lastUpdated) {
interestBearingAmount = _chargeInterest(interestBearingAmount, ratePerSecond, lastUpdated, block.timestamp);
}
return interestBearingAmount;
}
function _chargeInterest(uint interestBearingAmount, uint ratePerSecond, uint lastUpdated, uint current) internal pure returns (uint) {
return rmul(rpow(ratePerSecond, current - lastUpdated, ONE), interestBearingAmount);
}
// convert pie to debt/savings amount
function toAmount(uint chi, uint pie) public pure returns (uint) {
return rmul(pie, chi);
}
// convert debt/savings amount to pie
function toPie(uint chi, uint amount) public pure returns (uint) {
return rdivup(amount, chi);
}
function rpow(uint x, uint n, uint base) public pure returns (uint z) {
assembly {
switch x case 0 {switch n case 0 {z := base} default {z := 0}}
default {
switch mod(n, 2) case 0 { z := base } default { z := x }
let half := div(base, 2) // for rounding.
for { n := div(n, 2) } n { n := div(n,2) } {
let xx := mul(x, x)
if iszero(eq(div(xx, x), x)) { revert(0,0) }
let xxRound := add(xx, half)
if lt(xxRound, xx) { revert(0,0) }
x := div(xxRound, base)
if mod(n,2) {
let zx := mul(z, x)
if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
let zxRound := add(zx, half)
if lt(zxRound, zx) { revert(0,0) }
z := div(zxRound, base)
}
}
}
}
}
} | /* import "./math.sol"; */ | Comment | toAmount | function toAmount(uint chi, uint pie) public pure returns (uint) {
return rmul(pie, chi);
}
| // convert pie to debt/savings amount | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
1985,
2092
]
} | 9,675 |
||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Interest | contract Interest is Math {
// @notice This function provides compounding in seconds
// @param chi Accumulated interest rate over time
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated When the interest rate was last updated
// @param pie Total sum of all amounts accumulating under one interest rate, divided by that rate
// @return The new accumulated rate, as well as the difference between the debt calculated with the old and new accumulated rates.
function compounding(uint chi, uint ratePerSecond, uint lastUpdated, uint pie) public view returns (uint, uint) {
require(block.timestamp >= lastUpdated, "tinlake-math/invalid-timestamp");
require(chi != 0);
// instead of a interestBearingAmount we use a accumulated interest rate index (chi)
uint updatedChi = _chargeInterest(chi ,ratePerSecond, lastUpdated, block.timestamp);
return (updatedChi, safeSub(rmul(updatedChi, pie), rmul(chi, pie)));
}
// @notice This function charge interest on a interestBearingAmount
// @param interestBearingAmount is the interest bearing amount
// @param ratePerSecond Interest rate accumulation per second in RAD(10ˆ27)
// @param lastUpdated last time the interest has been charged
// @return interestBearingAmount + interest
function chargeInterest(uint interestBearingAmount, uint ratePerSecond, uint lastUpdated) public view returns (uint) {
if (block.timestamp >= lastUpdated) {
interestBearingAmount = _chargeInterest(interestBearingAmount, ratePerSecond, lastUpdated, block.timestamp);
}
return interestBearingAmount;
}
function _chargeInterest(uint interestBearingAmount, uint ratePerSecond, uint lastUpdated, uint current) internal pure returns (uint) {
return rmul(rpow(ratePerSecond, current - lastUpdated, ONE), interestBearingAmount);
}
// convert pie to debt/savings amount
function toAmount(uint chi, uint pie) public pure returns (uint) {
return rmul(pie, chi);
}
// convert debt/savings amount to pie
function toPie(uint chi, uint amount) public pure returns (uint) {
return rdivup(amount, chi);
}
function rpow(uint x, uint n, uint base) public pure returns (uint z) {
assembly {
switch x case 0 {switch n case 0 {z := base} default {z := 0}}
default {
switch mod(n, 2) case 0 { z := base } default { z := x }
let half := div(base, 2) // for rounding.
for { n := div(n, 2) } n { n := div(n,2) } {
let xx := mul(x, x)
if iszero(eq(div(xx, x), x)) { revert(0,0) }
let xxRound := add(xx, half)
if lt(xxRound, xx) { revert(0,0) }
x := div(xxRound, base)
if mod(n,2) {
let zx := mul(z, x)
if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
let zxRound := add(zx, half)
if lt(zxRound, zx) { revert(0,0) }
z := div(zxRound, base)
}
}
}
}
}
} | /* import "./math.sol"; */ | Comment | toPie | function toPie(uint chi, uint amount) public pure returns (uint) {
return rdivup(amount, chi);
}
| // convert debt/savings amount to pie | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
2136,
2248
]
} | 9,676 |
||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Definitions | contract Definitions is FixedPoint, Math {
function calcExpectedSeniorAsset(uint _seniorDebt, uint _seniorBalance) public pure returns(uint) {
return safeAdd(_seniorDebt, _seniorBalance);
}
// calculates the senior ratio
function calcSeniorRatio(uint seniorAsset, uint nav, uint reserve_) public pure returns(uint) {
// note: NAV + reserve == seniorAsset + juniorAsset (loop invariant: always true)
// if expectedSeniorAsset is passed ratio can be greater than ONE
uint assets = calcAssets(nav, reserve_);
if(assets == 0) {
return 0;
}
return rdiv(seniorAsset, assets);
}
function calcSeniorRatio(uint seniorRedeem, uint seniorSupply,
uint currSeniorAsset, uint newReserve, uint nav) public pure returns (uint seniorRatio) {
return calcSeniorRatio(calcSeniorAssetValue(seniorRedeem, seniorSupply,
currSeniorAsset, newReserve, nav), nav, newReserve);
}
// calculates the net wealth in the system
// NAV for ongoing loans and currency in reserve
function calcAssets(uint NAV, uint reserve_) public pure returns(uint) {
return safeAdd(NAV, reserve_);
}
// calculates a new senior asset value based on senior redeem and senior supply
function calcSeniorAssetValue(uint seniorRedeem, uint seniorSupply,
uint currSeniorAsset, uint reserve_, uint nav_) public pure returns (uint seniorAsset) {
seniorAsset = safeSub(safeAdd(currSeniorAsset, seniorSupply), seniorRedeem);
uint assets = calcAssets(nav_, reserve_);
if(seniorAsset > assets) {
seniorAsset = assets;
}
return seniorAsset;
}
// expected senior return if no losses occur
function calcExpectedSeniorAsset(uint seniorRedeem, uint seniorSupply, uint seniorBalance_, uint seniorDebt_) public pure returns(uint) {
return safeSub(safeAdd(safeAdd(seniorDebt_, seniorBalance_),seniorSupply), seniorRedeem);
}
} | // contract without a state which defines the relevant formulars for the assessor | LineComment | calcSeniorRatio | function calcSeniorRatio(uint seniorAsset, uint nav, uint reserve_) public pure returns(uint) {
// note: NAV + reserve == seniorAsset + juniorAsset (loop invariant: always true)
// if expectedSeniorAsset is passed ratio can be greater than ONE
uint assets = calcAssets(nav, reserve_);
if(assets == 0) {
return 0;
}
return rdiv(seniorAsset, assets);
}
| // calculates the senior ratio | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
242,
661
]
} | 9,677 |
||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Definitions | contract Definitions is FixedPoint, Math {
function calcExpectedSeniorAsset(uint _seniorDebt, uint _seniorBalance) public pure returns(uint) {
return safeAdd(_seniorDebt, _seniorBalance);
}
// calculates the senior ratio
function calcSeniorRatio(uint seniorAsset, uint nav, uint reserve_) public pure returns(uint) {
// note: NAV + reserve == seniorAsset + juniorAsset (loop invariant: always true)
// if expectedSeniorAsset is passed ratio can be greater than ONE
uint assets = calcAssets(nav, reserve_);
if(assets == 0) {
return 0;
}
return rdiv(seniorAsset, assets);
}
function calcSeniorRatio(uint seniorRedeem, uint seniorSupply,
uint currSeniorAsset, uint newReserve, uint nav) public pure returns (uint seniorRatio) {
return calcSeniorRatio(calcSeniorAssetValue(seniorRedeem, seniorSupply,
currSeniorAsset, newReserve, nav), nav, newReserve);
}
// calculates the net wealth in the system
// NAV for ongoing loans and currency in reserve
function calcAssets(uint NAV, uint reserve_) public pure returns(uint) {
return safeAdd(NAV, reserve_);
}
// calculates a new senior asset value based on senior redeem and senior supply
function calcSeniorAssetValue(uint seniorRedeem, uint seniorSupply,
uint currSeniorAsset, uint reserve_, uint nav_) public pure returns (uint seniorAsset) {
seniorAsset = safeSub(safeAdd(currSeniorAsset, seniorSupply), seniorRedeem);
uint assets = calcAssets(nav_, reserve_);
if(seniorAsset > assets) {
seniorAsset = assets;
}
return seniorAsset;
}
// expected senior return if no losses occur
function calcExpectedSeniorAsset(uint seniorRedeem, uint seniorSupply, uint seniorBalance_, uint seniorDebt_) public pure returns(uint) {
return safeSub(safeAdd(safeAdd(seniorDebt_, seniorBalance_),seniorSupply), seniorRedeem);
}
} | // contract without a state which defines the relevant formulars for the assessor | LineComment | calcAssets | function calcAssets(uint NAV, uint reserve_) public pure returns(uint) {
return safeAdd(NAV, reserve_);
}
| // calculates the net wealth in the system
// NAV for ongoing loans and currency in reserve | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
1085,
1206
]
} | 9,678 |
||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Definitions | contract Definitions is FixedPoint, Math {
function calcExpectedSeniorAsset(uint _seniorDebt, uint _seniorBalance) public pure returns(uint) {
return safeAdd(_seniorDebt, _seniorBalance);
}
// calculates the senior ratio
function calcSeniorRatio(uint seniorAsset, uint nav, uint reserve_) public pure returns(uint) {
// note: NAV + reserve == seniorAsset + juniorAsset (loop invariant: always true)
// if expectedSeniorAsset is passed ratio can be greater than ONE
uint assets = calcAssets(nav, reserve_);
if(assets == 0) {
return 0;
}
return rdiv(seniorAsset, assets);
}
function calcSeniorRatio(uint seniorRedeem, uint seniorSupply,
uint currSeniorAsset, uint newReserve, uint nav) public pure returns (uint seniorRatio) {
return calcSeniorRatio(calcSeniorAssetValue(seniorRedeem, seniorSupply,
currSeniorAsset, newReserve, nav), nav, newReserve);
}
// calculates the net wealth in the system
// NAV for ongoing loans and currency in reserve
function calcAssets(uint NAV, uint reserve_) public pure returns(uint) {
return safeAdd(NAV, reserve_);
}
// calculates a new senior asset value based on senior redeem and senior supply
function calcSeniorAssetValue(uint seniorRedeem, uint seniorSupply,
uint currSeniorAsset, uint reserve_, uint nav_) public pure returns (uint seniorAsset) {
seniorAsset = safeSub(safeAdd(currSeniorAsset, seniorSupply), seniorRedeem);
uint assets = calcAssets(nav_, reserve_);
if(seniorAsset > assets) {
seniorAsset = assets;
}
return seniorAsset;
}
// expected senior return if no losses occur
function calcExpectedSeniorAsset(uint seniorRedeem, uint seniorSupply, uint seniorBalance_, uint seniorDebt_) public pure returns(uint) {
return safeSub(safeAdd(safeAdd(seniorDebt_, seniorBalance_),seniorSupply), seniorRedeem);
}
} | // contract without a state which defines the relevant formulars for the assessor | LineComment | calcSeniorAssetValue | function calcSeniorAssetValue(uint seniorRedeem, uint seniorSupply,
uint currSeniorAsset, uint reserve_, uint nav_) public pure returns (uint seniorAsset) {
seniorAsset = safeSub(safeAdd(currSeniorAsset, seniorSupply), seniorRedeem);
uint assets = calcAssets(nav_, reserve_);
if(seniorAsset > assets) {
seniorAsset = assets;
}
return seniorAsset;
}
| // calculates a new senior asset value based on senior redeem and senior supply | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
1292,
1711
]
} | 9,679 |
||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Definitions | contract Definitions is FixedPoint, Math {
function calcExpectedSeniorAsset(uint _seniorDebt, uint _seniorBalance) public pure returns(uint) {
return safeAdd(_seniorDebt, _seniorBalance);
}
// calculates the senior ratio
function calcSeniorRatio(uint seniorAsset, uint nav, uint reserve_) public pure returns(uint) {
// note: NAV + reserve == seniorAsset + juniorAsset (loop invariant: always true)
// if expectedSeniorAsset is passed ratio can be greater than ONE
uint assets = calcAssets(nav, reserve_);
if(assets == 0) {
return 0;
}
return rdiv(seniorAsset, assets);
}
function calcSeniorRatio(uint seniorRedeem, uint seniorSupply,
uint currSeniorAsset, uint newReserve, uint nav) public pure returns (uint seniorRatio) {
return calcSeniorRatio(calcSeniorAssetValue(seniorRedeem, seniorSupply,
currSeniorAsset, newReserve, nav), nav, newReserve);
}
// calculates the net wealth in the system
// NAV for ongoing loans and currency in reserve
function calcAssets(uint NAV, uint reserve_) public pure returns(uint) {
return safeAdd(NAV, reserve_);
}
// calculates a new senior asset value based on senior redeem and senior supply
function calcSeniorAssetValue(uint seniorRedeem, uint seniorSupply,
uint currSeniorAsset, uint reserve_, uint nav_) public pure returns (uint seniorAsset) {
seniorAsset = safeSub(safeAdd(currSeniorAsset, seniorSupply), seniorRedeem);
uint assets = calcAssets(nav_, reserve_);
if(seniorAsset > assets) {
seniorAsset = assets;
}
return seniorAsset;
}
// expected senior return if no losses occur
function calcExpectedSeniorAsset(uint seniorRedeem, uint seniorSupply, uint seniorBalance_, uint seniorDebt_) public pure returns(uint) {
return safeSub(safeAdd(safeAdd(seniorDebt_, seniorBalance_),seniorSupply), seniorRedeem);
}
} | // contract without a state which defines the relevant formulars for the assessor | LineComment | calcExpectedSeniorAsset | function calcExpectedSeniorAsset(uint seniorRedeem, uint seniorSupply, uint seniorBalance_, uint seniorDebt_) public pure returns(uint) {
return safeSub(safeAdd(safeAdd(seniorDebt_, seniorBalance_),seniorSupply), seniorRedeem);
}
| // expected senior return if no losses occur | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
1762,
2007
]
} | 9,680 |
||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Assessor | contract Assessor is Definitions, Auth, Interest {
// senior ratio from the last epoch executed
Fixed27 public seniorRatio;
// the seniorAsset value is stored in two variables
// seniorDebt is the interest bearing amount for senior
uint public seniorDebt_;
// senior balance is the rest which is not used as interest
// bearing amount
uint public seniorBalance_;
// interest rate per second for senior tranche
Fixed27 public seniorInterestRate;
// last time the senior interest has been updated
uint public lastUpdateSeniorInterest;
Fixed27 public maxSeniorRatio;
Fixed27 public minSeniorRatio;
uint public maxReserve;
uint public creditBufferTime = 1 days;
TrancheLike_2 public seniorTranche;
TrancheLike_2 public juniorTranche;
NAVFeedLike_3 public navFeed;
ReserveLike_4 public reserve;
LendingAdapter_1 public lending;
uint public constant supplyTolerance = 5;
event Depend(bytes32 indexed contractName, address addr);
event File(bytes32 indexed name, uint value);
constructor() {
seniorInterestRate.value = ONE;
lastUpdateSeniorInterest = block.timestamp;
seniorRatio.value = 0;
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
function depend(bytes32 contractName, address addr) public auth {
if (contractName == "navFeed") {
navFeed = NAVFeedLike_3(addr);
} else if (contractName == "seniorTranche") {
seniorTranche = TrancheLike_2(addr);
} else if (contractName == "juniorTranche") {
juniorTranche = TrancheLike_2(addr);
} else if (contractName == "reserve") {
reserve = ReserveLike_4(addr);
} else if (contractName == "lending") {
lending = LendingAdapter_1(addr);
} else revert();
emit Depend(contractName, addr);
}
function file(bytes32 name, uint value) public auth {
if (name == "seniorInterestRate") {
dripSeniorDebt();
seniorInterestRate = Fixed27(value);
} else if (name == "maxReserve") {
maxReserve = value;
} else if (name == "maxSeniorRatio") {
require(value > minSeniorRatio.value, "value-too-small");
maxSeniorRatio = Fixed27(value);
} else if (name == "minSeniorRatio") {
require(value < maxSeniorRatio.value, "value-too-big");
minSeniorRatio = Fixed27(value);
} else if (name == "creditBufferTime") {
creditBufferTime = value;
} else {
revert("unknown-variable");
}
emit File(name, value);
}
function reBalance() public {
reBalance(calcExpectedSeniorAsset(seniorBalance_, dripSeniorDebt()));
}
function reBalance(uint seniorAsset_) internal {
// re-balancing according to new ratio
// we use the approximated NAV here because during the submission period
// new loans might have been repaid in the meanwhile which are not considered in the epochNAV
uint nav_ = navFeed.approximatedNAV();
uint reserve_ = reserve.totalBalance();
uint seniorRatio_ = calcSeniorRatio(seniorAsset_, nav_, reserve_);
// in that case the entire juniorAsset is lost
// the senior would own everything that' left
if(seniorRatio_ > ONE) {
seniorRatio_ = ONE;
}
seniorDebt_ = rmul(nav_, seniorRatio_);
if(seniorDebt_ > seniorAsset_) {
seniorDebt_ = seniorAsset_;
seniorBalance_ = 0;
} else {
seniorBalance_ = safeSub(seniorAsset_, seniorDebt_);
}
seniorRatio = Fixed27(seniorRatio_);
}
function changeSeniorAsset(uint seniorSupply, uint seniorRedeem) external auth {
reBalance(calcExpectedSeniorAsset(seniorRedeem, seniorSupply, seniorBalance_, dripSeniorDebt()));
}
function seniorRatioBounds() public view returns (uint minSeniorRatio_, uint maxSeniorRatio_) {
return (minSeniorRatio.value, maxSeniorRatio.value);
}
function calcUpdateNAV() external returns (uint) {
return navFeed.calcUpdateNAV();
}
function calcSeniorTokenPrice() external view returns(uint) {
return calcSeniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcSeniorTokenPrice(uint nav_, uint) public view returns(uint) {
return _calcSeniorTokenPrice(nav_, reserve.totalBalance());
}
function calcJuniorTokenPrice() external view returns(uint) {
return _calcJuniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcJuniorTokenPrice(uint nav_, uint) public view returns (uint) {
return _calcJuniorTokenPrice(nav_, reserve.totalBalance());
}
function calcTokenPrices() external view returns (uint, uint) {
uint epochNAV = navFeed.approximatedNAV();
uint epochReserve = reserve.totalBalance();
return calcTokenPrices(epochNAV, epochReserve);
}
function calcTokenPrices(uint epochNAV, uint epochReserve) public view returns (uint, uint) {
return (_calcJuniorTokenPrice(epochNAV, epochReserve), _calcSeniorTokenPrice(epochNAV, epochReserve));
}
function _calcSeniorTokenPrice(uint nav_, uint reserve_) internal view returns(uint) {
// the coordinator interface will pass the reserveAvailable
if ((nav_ == 0 && reserve_ == 0) || seniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
seniorAssetValue = totalAssets;
}
return rdiv(seniorAssetValue, seniorTranche.tokenSupply());
}
function _calcJuniorTokenPrice(uint nav_, uint reserve_) internal view returns (uint) {
if ((nav_ == 0 && reserve_ == 0) || juniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline from mkr
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
return 0;
}
// the junior tranche only needs to pay for the mkr over-collateralization if
// the mkr vault is liquidated, if that is true juniorStake=0
uint juniorStake = 0;
if (address(lending) != address(0)) {
juniorStake = lending.juniorStake();
}
return rdiv(safeAdd(safeSub(totalAssets, seniorAssetValue), juniorStake),
juniorTranche.tokenSupply());
}
function dripSeniorDebt() public returns (uint) {
seniorDebt_ = seniorDebt();
lastUpdateSeniorInterest = block.timestamp;
return seniorDebt_;
}
function seniorDebt() public view returns (uint) {
if (block.timestamp >= lastUpdateSeniorInterest) {
return chargeInterest(seniorDebt_, seniorInterestRate.value, lastUpdateSeniorInterest);
}
return seniorDebt_;
}
function seniorBalance() public view returns(uint) {
return safeAdd(seniorBalance_, remainingOvercollCredit());
}
function effectiveSeniorBalance() public view returns(uint) {
return seniorBalance_;
}
function effectiveTotalBalance() public view returns(uint) {
return reserve.totalBalance();
}
function totalBalance() public view returns(uint) {
return safeAdd(reserve.totalBalance(), remainingCredit());
}
// returns the current NAV
function currentNAV() public view returns(uint) {
return navFeed.currentNAV();
}
// returns the approximated NAV for gas-performance reasons
function getNAV() public view returns(uint) {
return navFeed.approximatedNAV();
}
// changes the total amount available for borrowing loans
function changeBorrowAmountEpoch(uint currencyAmount) public auth {
reserve.file("currencyAvailable", currencyAmount);
}
function borrowAmountEpoch() public view returns(uint) {
return reserve.currencyAvailable();
}
// returns the current junior ratio protection in the Tinlake
// juniorRatio is denominated in RAY (10^27)
function calcJuniorRatio() public view returns(uint) {
uint seniorAsset = safeAdd(seniorDebt(), seniorBalance_);
uint assets = safeAdd(navFeed.approximatedNAV(), reserve.totalBalance());
if(seniorAsset == 0 && assets == 0) {
return 0;
}
if(seniorAsset == 0 && assets > 0) {
return ONE;
}
if (seniorAsset > assets) {
return 0;
}
return safeSub(ONE, rdiv(seniorAsset, assets));
}
// returns the remainingCredit plus a buffer for the interest increase
function remainingCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
// over the time the remainingCredit will decrease because of the accumulated debt interest
// therefore a buffer is reduced from the remainingCredit to prevent the usage of currency which is not available
uint debt = lending.debt();
uint stabilityBuffer = safeSub(rmul(rpow(lending.stabilityFee(),
creditBufferTime, ONE), debt), debt);
uint remainingCredit_ = lending.remainingCredit();
if(remainingCredit_ > stabilityBuffer) {
return safeSub(remainingCredit_, stabilityBuffer);
}
return 0;
}
function remainingOvercollCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
return lending.calcOvercollAmount(remainingCredit());
}
} | currentNAV | function currentNAV() public view returns(uint) {
return navFeed.currentNAV();
}
| // returns the current NAV | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
8305,
8401
]
} | 9,681 |
||||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Assessor | contract Assessor is Definitions, Auth, Interest {
// senior ratio from the last epoch executed
Fixed27 public seniorRatio;
// the seniorAsset value is stored in two variables
// seniorDebt is the interest bearing amount for senior
uint public seniorDebt_;
// senior balance is the rest which is not used as interest
// bearing amount
uint public seniorBalance_;
// interest rate per second for senior tranche
Fixed27 public seniorInterestRate;
// last time the senior interest has been updated
uint public lastUpdateSeniorInterest;
Fixed27 public maxSeniorRatio;
Fixed27 public minSeniorRatio;
uint public maxReserve;
uint public creditBufferTime = 1 days;
TrancheLike_2 public seniorTranche;
TrancheLike_2 public juniorTranche;
NAVFeedLike_3 public navFeed;
ReserveLike_4 public reserve;
LendingAdapter_1 public lending;
uint public constant supplyTolerance = 5;
event Depend(bytes32 indexed contractName, address addr);
event File(bytes32 indexed name, uint value);
constructor() {
seniorInterestRate.value = ONE;
lastUpdateSeniorInterest = block.timestamp;
seniorRatio.value = 0;
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
function depend(bytes32 contractName, address addr) public auth {
if (contractName == "navFeed") {
navFeed = NAVFeedLike_3(addr);
} else if (contractName == "seniorTranche") {
seniorTranche = TrancheLike_2(addr);
} else if (contractName == "juniorTranche") {
juniorTranche = TrancheLike_2(addr);
} else if (contractName == "reserve") {
reserve = ReserveLike_4(addr);
} else if (contractName == "lending") {
lending = LendingAdapter_1(addr);
} else revert();
emit Depend(contractName, addr);
}
function file(bytes32 name, uint value) public auth {
if (name == "seniorInterestRate") {
dripSeniorDebt();
seniorInterestRate = Fixed27(value);
} else if (name == "maxReserve") {
maxReserve = value;
} else if (name == "maxSeniorRatio") {
require(value > minSeniorRatio.value, "value-too-small");
maxSeniorRatio = Fixed27(value);
} else if (name == "minSeniorRatio") {
require(value < maxSeniorRatio.value, "value-too-big");
minSeniorRatio = Fixed27(value);
} else if (name == "creditBufferTime") {
creditBufferTime = value;
} else {
revert("unknown-variable");
}
emit File(name, value);
}
function reBalance() public {
reBalance(calcExpectedSeniorAsset(seniorBalance_, dripSeniorDebt()));
}
function reBalance(uint seniorAsset_) internal {
// re-balancing according to new ratio
// we use the approximated NAV here because during the submission period
// new loans might have been repaid in the meanwhile which are not considered in the epochNAV
uint nav_ = navFeed.approximatedNAV();
uint reserve_ = reserve.totalBalance();
uint seniorRatio_ = calcSeniorRatio(seniorAsset_, nav_, reserve_);
// in that case the entire juniorAsset is lost
// the senior would own everything that' left
if(seniorRatio_ > ONE) {
seniorRatio_ = ONE;
}
seniorDebt_ = rmul(nav_, seniorRatio_);
if(seniorDebt_ > seniorAsset_) {
seniorDebt_ = seniorAsset_;
seniorBalance_ = 0;
} else {
seniorBalance_ = safeSub(seniorAsset_, seniorDebt_);
}
seniorRatio = Fixed27(seniorRatio_);
}
function changeSeniorAsset(uint seniorSupply, uint seniorRedeem) external auth {
reBalance(calcExpectedSeniorAsset(seniorRedeem, seniorSupply, seniorBalance_, dripSeniorDebt()));
}
function seniorRatioBounds() public view returns (uint minSeniorRatio_, uint maxSeniorRatio_) {
return (minSeniorRatio.value, maxSeniorRatio.value);
}
function calcUpdateNAV() external returns (uint) {
return navFeed.calcUpdateNAV();
}
function calcSeniorTokenPrice() external view returns(uint) {
return calcSeniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcSeniorTokenPrice(uint nav_, uint) public view returns(uint) {
return _calcSeniorTokenPrice(nav_, reserve.totalBalance());
}
function calcJuniorTokenPrice() external view returns(uint) {
return _calcJuniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcJuniorTokenPrice(uint nav_, uint) public view returns (uint) {
return _calcJuniorTokenPrice(nav_, reserve.totalBalance());
}
function calcTokenPrices() external view returns (uint, uint) {
uint epochNAV = navFeed.approximatedNAV();
uint epochReserve = reserve.totalBalance();
return calcTokenPrices(epochNAV, epochReserve);
}
function calcTokenPrices(uint epochNAV, uint epochReserve) public view returns (uint, uint) {
return (_calcJuniorTokenPrice(epochNAV, epochReserve), _calcSeniorTokenPrice(epochNAV, epochReserve));
}
function _calcSeniorTokenPrice(uint nav_, uint reserve_) internal view returns(uint) {
// the coordinator interface will pass the reserveAvailable
if ((nav_ == 0 && reserve_ == 0) || seniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
seniorAssetValue = totalAssets;
}
return rdiv(seniorAssetValue, seniorTranche.tokenSupply());
}
function _calcJuniorTokenPrice(uint nav_, uint reserve_) internal view returns (uint) {
if ((nav_ == 0 && reserve_ == 0) || juniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline from mkr
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
return 0;
}
// the junior tranche only needs to pay for the mkr over-collateralization if
// the mkr vault is liquidated, if that is true juniorStake=0
uint juniorStake = 0;
if (address(lending) != address(0)) {
juniorStake = lending.juniorStake();
}
return rdiv(safeAdd(safeSub(totalAssets, seniorAssetValue), juniorStake),
juniorTranche.tokenSupply());
}
function dripSeniorDebt() public returns (uint) {
seniorDebt_ = seniorDebt();
lastUpdateSeniorInterest = block.timestamp;
return seniorDebt_;
}
function seniorDebt() public view returns (uint) {
if (block.timestamp >= lastUpdateSeniorInterest) {
return chargeInterest(seniorDebt_, seniorInterestRate.value, lastUpdateSeniorInterest);
}
return seniorDebt_;
}
function seniorBalance() public view returns(uint) {
return safeAdd(seniorBalance_, remainingOvercollCredit());
}
function effectiveSeniorBalance() public view returns(uint) {
return seniorBalance_;
}
function effectiveTotalBalance() public view returns(uint) {
return reserve.totalBalance();
}
function totalBalance() public view returns(uint) {
return safeAdd(reserve.totalBalance(), remainingCredit());
}
// returns the current NAV
function currentNAV() public view returns(uint) {
return navFeed.currentNAV();
}
// returns the approximated NAV for gas-performance reasons
function getNAV() public view returns(uint) {
return navFeed.approximatedNAV();
}
// changes the total amount available for borrowing loans
function changeBorrowAmountEpoch(uint currencyAmount) public auth {
reserve.file("currencyAvailable", currencyAmount);
}
function borrowAmountEpoch() public view returns(uint) {
return reserve.currencyAvailable();
}
// returns the current junior ratio protection in the Tinlake
// juniorRatio is denominated in RAY (10^27)
function calcJuniorRatio() public view returns(uint) {
uint seniorAsset = safeAdd(seniorDebt(), seniorBalance_);
uint assets = safeAdd(navFeed.approximatedNAV(), reserve.totalBalance());
if(seniorAsset == 0 && assets == 0) {
return 0;
}
if(seniorAsset == 0 && assets > 0) {
return ONE;
}
if (seniorAsset > assets) {
return 0;
}
return safeSub(ONE, rdiv(seniorAsset, assets));
}
// returns the remainingCredit plus a buffer for the interest increase
function remainingCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
// over the time the remainingCredit will decrease because of the accumulated debt interest
// therefore a buffer is reduced from the remainingCredit to prevent the usage of currency which is not available
uint debt = lending.debt();
uint stabilityBuffer = safeSub(rmul(rpow(lending.stabilityFee(),
creditBufferTime, ONE), debt), debt);
uint remainingCredit_ = lending.remainingCredit();
if(remainingCredit_ > stabilityBuffer) {
return safeSub(remainingCredit_, stabilityBuffer);
}
return 0;
}
function remainingOvercollCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
return lending.calcOvercollAmount(remainingCredit());
}
} | getNAV | function getNAV() public view returns(uint) {
return navFeed.approximatedNAV();
}
| // returns the approximated NAV for gas-performance reasons | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
8467,
8564
]
} | 9,682 |
||||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Assessor | contract Assessor is Definitions, Auth, Interest {
// senior ratio from the last epoch executed
Fixed27 public seniorRatio;
// the seniorAsset value is stored in two variables
// seniorDebt is the interest bearing amount for senior
uint public seniorDebt_;
// senior balance is the rest which is not used as interest
// bearing amount
uint public seniorBalance_;
// interest rate per second for senior tranche
Fixed27 public seniorInterestRate;
// last time the senior interest has been updated
uint public lastUpdateSeniorInterest;
Fixed27 public maxSeniorRatio;
Fixed27 public minSeniorRatio;
uint public maxReserve;
uint public creditBufferTime = 1 days;
TrancheLike_2 public seniorTranche;
TrancheLike_2 public juniorTranche;
NAVFeedLike_3 public navFeed;
ReserveLike_4 public reserve;
LendingAdapter_1 public lending;
uint public constant supplyTolerance = 5;
event Depend(bytes32 indexed contractName, address addr);
event File(bytes32 indexed name, uint value);
constructor() {
seniorInterestRate.value = ONE;
lastUpdateSeniorInterest = block.timestamp;
seniorRatio.value = 0;
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
function depend(bytes32 contractName, address addr) public auth {
if (contractName == "navFeed") {
navFeed = NAVFeedLike_3(addr);
} else if (contractName == "seniorTranche") {
seniorTranche = TrancheLike_2(addr);
} else if (contractName == "juniorTranche") {
juniorTranche = TrancheLike_2(addr);
} else if (contractName == "reserve") {
reserve = ReserveLike_4(addr);
} else if (contractName == "lending") {
lending = LendingAdapter_1(addr);
} else revert();
emit Depend(contractName, addr);
}
function file(bytes32 name, uint value) public auth {
if (name == "seniorInterestRate") {
dripSeniorDebt();
seniorInterestRate = Fixed27(value);
} else if (name == "maxReserve") {
maxReserve = value;
} else if (name == "maxSeniorRatio") {
require(value > minSeniorRatio.value, "value-too-small");
maxSeniorRatio = Fixed27(value);
} else if (name == "minSeniorRatio") {
require(value < maxSeniorRatio.value, "value-too-big");
minSeniorRatio = Fixed27(value);
} else if (name == "creditBufferTime") {
creditBufferTime = value;
} else {
revert("unknown-variable");
}
emit File(name, value);
}
function reBalance() public {
reBalance(calcExpectedSeniorAsset(seniorBalance_, dripSeniorDebt()));
}
function reBalance(uint seniorAsset_) internal {
// re-balancing according to new ratio
// we use the approximated NAV here because during the submission period
// new loans might have been repaid in the meanwhile which are not considered in the epochNAV
uint nav_ = navFeed.approximatedNAV();
uint reserve_ = reserve.totalBalance();
uint seniorRatio_ = calcSeniorRatio(seniorAsset_, nav_, reserve_);
// in that case the entire juniorAsset is lost
// the senior would own everything that' left
if(seniorRatio_ > ONE) {
seniorRatio_ = ONE;
}
seniorDebt_ = rmul(nav_, seniorRatio_);
if(seniorDebt_ > seniorAsset_) {
seniorDebt_ = seniorAsset_;
seniorBalance_ = 0;
} else {
seniorBalance_ = safeSub(seniorAsset_, seniorDebt_);
}
seniorRatio = Fixed27(seniorRatio_);
}
function changeSeniorAsset(uint seniorSupply, uint seniorRedeem) external auth {
reBalance(calcExpectedSeniorAsset(seniorRedeem, seniorSupply, seniorBalance_, dripSeniorDebt()));
}
function seniorRatioBounds() public view returns (uint minSeniorRatio_, uint maxSeniorRatio_) {
return (minSeniorRatio.value, maxSeniorRatio.value);
}
function calcUpdateNAV() external returns (uint) {
return navFeed.calcUpdateNAV();
}
function calcSeniorTokenPrice() external view returns(uint) {
return calcSeniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcSeniorTokenPrice(uint nav_, uint) public view returns(uint) {
return _calcSeniorTokenPrice(nav_, reserve.totalBalance());
}
function calcJuniorTokenPrice() external view returns(uint) {
return _calcJuniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcJuniorTokenPrice(uint nav_, uint) public view returns (uint) {
return _calcJuniorTokenPrice(nav_, reserve.totalBalance());
}
function calcTokenPrices() external view returns (uint, uint) {
uint epochNAV = navFeed.approximatedNAV();
uint epochReserve = reserve.totalBalance();
return calcTokenPrices(epochNAV, epochReserve);
}
function calcTokenPrices(uint epochNAV, uint epochReserve) public view returns (uint, uint) {
return (_calcJuniorTokenPrice(epochNAV, epochReserve), _calcSeniorTokenPrice(epochNAV, epochReserve));
}
function _calcSeniorTokenPrice(uint nav_, uint reserve_) internal view returns(uint) {
// the coordinator interface will pass the reserveAvailable
if ((nav_ == 0 && reserve_ == 0) || seniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
seniorAssetValue = totalAssets;
}
return rdiv(seniorAssetValue, seniorTranche.tokenSupply());
}
function _calcJuniorTokenPrice(uint nav_, uint reserve_) internal view returns (uint) {
if ((nav_ == 0 && reserve_ == 0) || juniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline from mkr
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
return 0;
}
// the junior tranche only needs to pay for the mkr over-collateralization if
// the mkr vault is liquidated, if that is true juniorStake=0
uint juniorStake = 0;
if (address(lending) != address(0)) {
juniorStake = lending.juniorStake();
}
return rdiv(safeAdd(safeSub(totalAssets, seniorAssetValue), juniorStake),
juniorTranche.tokenSupply());
}
function dripSeniorDebt() public returns (uint) {
seniorDebt_ = seniorDebt();
lastUpdateSeniorInterest = block.timestamp;
return seniorDebt_;
}
function seniorDebt() public view returns (uint) {
if (block.timestamp >= lastUpdateSeniorInterest) {
return chargeInterest(seniorDebt_, seniorInterestRate.value, lastUpdateSeniorInterest);
}
return seniorDebt_;
}
function seniorBalance() public view returns(uint) {
return safeAdd(seniorBalance_, remainingOvercollCredit());
}
function effectiveSeniorBalance() public view returns(uint) {
return seniorBalance_;
}
function effectiveTotalBalance() public view returns(uint) {
return reserve.totalBalance();
}
function totalBalance() public view returns(uint) {
return safeAdd(reserve.totalBalance(), remainingCredit());
}
// returns the current NAV
function currentNAV() public view returns(uint) {
return navFeed.currentNAV();
}
// returns the approximated NAV for gas-performance reasons
function getNAV() public view returns(uint) {
return navFeed.approximatedNAV();
}
// changes the total amount available for borrowing loans
function changeBorrowAmountEpoch(uint currencyAmount) public auth {
reserve.file("currencyAvailable", currencyAmount);
}
function borrowAmountEpoch() public view returns(uint) {
return reserve.currencyAvailable();
}
// returns the current junior ratio protection in the Tinlake
// juniorRatio is denominated in RAY (10^27)
function calcJuniorRatio() public view returns(uint) {
uint seniorAsset = safeAdd(seniorDebt(), seniorBalance_);
uint assets = safeAdd(navFeed.approximatedNAV(), reserve.totalBalance());
if(seniorAsset == 0 && assets == 0) {
return 0;
}
if(seniorAsset == 0 && assets > 0) {
return ONE;
}
if (seniorAsset > assets) {
return 0;
}
return safeSub(ONE, rdiv(seniorAsset, assets));
}
// returns the remainingCredit plus a buffer for the interest increase
function remainingCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
// over the time the remainingCredit will decrease because of the accumulated debt interest
// therefore a buffer is reduced from the remainingCredit to prevent the usage of currency which is not available
uint debt = lending.debt();
uint stabilityBuffer = safeSub(rmul(rpow(lending.stabilityFee(),
creditBufferTime, ONE), debt), debt);
uint remainingCredit_ = lending.remainingCredit();
if(remainingCredit_ > stabilityBuffer) {
return safeSub(remainingCredit_, stabilityBuffer);
}
return 0;
}
function remainingOvercollCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
return lending.calcOvercollAmount(remainingCredit());
}
} | changeBorrowAmountEpoch | function changeBorrowAmountEpoch(uint currencyAmount) public auth {
reserve.file("currencyAvailable", currencyAmount);
}
| // changes the total amount available for borrowing loans | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
8628,
8764
]
} | 9,683 |
||||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Assessor | contract Assessor is Definitions, Auth, Interest {
// senior ratio from the last epoch executed
Fixed27 public seniorRatio;
// the seniorAsset value is stored in two variables
// seniorDebt is the interest bearing amount for senior
uint public seniorDebt_;
// senior balance is the rest which is not used as interest
// bearing amount
uint public seniorBalance_;
// interest rate per second for senior tranche
Fixed27 public seniorInterestRate;
// last time the senior interest has been updated
uint public lastUpdateSeniorInterest;
Fixed27 public maxSeniorRatio;
Fixed27 public minSeniorRatio;
uint public maxReserve;
uint public creditBufferTime = 1 days;
TrancheLike_2 public seniorTranche;
TrancheLike_2 public juniorTranche;
NAVFeedLike_3 public navFeed;
ReserveLike_4 public reserve;
LendingAdapter_1 public lending;
uint public constant supplyTolerance = 5;
event Depend(bytes32 indexed contractName, address addr);
event File(bytes32 indexed name, uint value);
constructor() {
seniorInterestRate.value = ONE;
lastUpdateSeniorInterest = block.timestamp;
seniorRatio.value = 0;
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
function depend(bytes32 contractName, address addr) public auth {
if (contractName == "navFeed") {
navFeed = NAVFeedLike_3(addr);
} else if (contractName == "seniorTranche") {
seniorTranche = TrancheLike_2(addr);
} else if (contractName == "juniorTranche") {
juniorTranche = TrancheLike_2(addr);
} else if (contractName == "reserve") {
reserve = ReserveLike_4(addr);
} else if (contractName == "lending") {
lending = LendingAdapter_1(addr);
} else revert();
emit Depend(contractName, addr);
}
function file(bytes32 name, uint value) public auth {
if (name == "seniorInterestRate") {
dripSeniorDebt();
seniorInterestRate = Fixed27(value);
} else if (name == "maxReserve") {
maxReserve = value;
} else if (name == "maxSeniorRatio") {
require(value > minSeniorRatio.value, "value-too-small");
maxSeniorRatio = Fixed27(value);
} else if (name == "minSeniorRatio") {
require(value < maxSeniorRatio.value, "value-too-big");
minSeniorRatio = Fixed27(value);
} else if (name == "creditBufferTime") {
creditBufferTime = value;
} else {
revert("unknown-variable");
}
emit File(name, value);
}
function reBalance() public {
reBalance(calcExpectedSeniorAsset(seniorBalance_, dripSeniorDebt()));
}
function reBalance(uint seniorAsset_) internal {
// re-balancing according to new ratio
// we use the approximated NAV here because during the submission period
// new loans might have been repaid in the meanwhile which are not considered in the epochNAV
uint nav_ = navFeed.approximatedNAV();
uint reserve_ = reserve.totalBalance();
uint seniorRatio_ = calcSeniorRatio(seniorAsset_, nav_, reserve_);
// in that case the entire juniorAsset is lost
// the senior would own everything that' left
if(seniorRatio_ > ONE) {
seniorRatio_ = ONE;
}
seniorDebt_ = rmul(nav_, seniorRatio_);
if(seniorDebt_ > seniorAsset_) {
seniorDebt_ = seniorAsset_;
seniorBalance_ = 0;
} else {
seniorBalance_ = safeSub(seniorAsset_, seniorDebt_);
}
seniorRatio = Fixed27(seniorRatio_);
}
function changeSeniorAsset(uint seniorSupply, uint seniorRedeem) external auth {
reBalance(calcExpectedSeniorAsset(seniorRedeem, seniorSupply, seniorBalance_, dripSeniorDebt()));
}
function seniorRatioBounds() public view returns (uint minSeniorRatio_, uint maxSeniorRatio_) {
return (minSeniorRatio.value, maxSeniorRatio.value);
}
function calcUpdateNAV() external returns (uint) {
return navFeed.calcUpdateNAV();
}
function calcSeniorTokenPrice() external view returns(uint) {
return calcSeniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcSeniorTokenPrice(uint nav_, uint) public view returns(uint) {
return _calcSeniorTokenPrice(nav_, reserve.totalBalance());
}
function calcJuniorTokenPrice() external view returns(uint) {
return _calcJuniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcJuniorTokenPrice(uint nav_, uint) public view returns (uint) {
return _calcJuniorTokenPrice(nav_, reserve.totalBalance());
}
function calcTokenPrices() external view returns (uint, uint) {
uint epochNAV = navFeed.approximatedNAV();
uint epochReserve = reserve.totalBalance();
return calcTokenPrices(epochNAV, epochReserve);
}
function calcTokenPrices(uint epochNAV, uint epochReserve) public view returns (uint, uint) {
return (_calcJuniorTokenPrice(epochNAV, epochReserve), _calcSeniorTokenPrice(epochNAV, epochReserve));
}
function _calcSeniorTokenPrice(uint nav_, uint reserve_) internal view returns(uint) {
// the coordinator interface will pass the reserveAvailable
if ((nav_ == 0 && reserve_ == 0) || seniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
seniorAssetValue = totalAssets;
}
return rdiv(seniorAssetValue, seniorTranche.tokenSupply());
}
function _calcJuniorTokenPrice(uint nav_, uint reserve_) internal view returns (uint) {
if ((nav_ == 0 && reserve_ == 0) || juniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline from mkr
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
return 0;
}
// the junior tranche only needs to pay for the mkr over-collateralization if
// the mkr vault is liquidated, if that is true juniorStake=0
uint juniorStake = 0;
if (address(lending) != address(0)) {
juniorStake = lending.juniorStake();
}
return rdiv(safeAdd(safeSub(totalAssets, seniorAssetValue), juniorStake),
juniorTranche.tokenSupply());
}
function dripSeniorDebt() public returns (uint) {
seniorDebt_ = seniorDebt();
lastUpdateSeniorInterest = block.timestamp;
return seniorDebt_;
}
function seniorDebt() public view returns (uint) {
if (block.timestamp >= lastUpdateSeniorInterest) {
return chargeInterest(seniorDebt_, seniorInterestRate.value, lastUpdateSeniorInterest);
}
return seniorDebt_;
}
function seniorBalance() public view returns(uint) {
return safeAdd(seniorBalance_, remainingOvercollCredit());
}
function effectiveSeniorBalance() public view returns(uint) {
return seniorBalance_;
}
function effectiveTotalBalance() public view returns(uint) {
return reserve.totalBalance();
}
function totalBalance() public view returns(uint) {
return safeAdd(reserve.totalBalance(), remainingCredit());
}
// returns the current NAV
function currentNAV() public view returns(uint) {
return navFeed.currentNAV();
}
// returns the approximated NAV for gas-performance reasons
function getNAV() public view returns(uint) {
return navFeed.approximatedNAV();
}
// changes the total amount available for borrowing loans
function changeBorrowAmountEpoch(uint currencyAmount) public auth {
reserve.file("currencyAvailable", currencyAmount);
}
function borrowAmountEpoch() public view returns(uint) {
return reserve.currencyAvailable();
}
// returns the current junior ratio protection in the Tinlake
// juniorRatio is denominated in RAY (10^27)
function calcJuniorRatio() public view returns(uint) {
uint seniorAsset = safeAdd(seniorDebt(), seniorBalance_);
uint assets = safeAdd(navFeed.approximatedNAV(), reserve.totalBalance());
if(seniorAsset == 0 && assets == 0) {
return 0;
}
if(seniorAsset == 0 && assets > 0) {
return ONE;
}
if (seniorAsset > assets) {
return 0;
}
return safeSub(ONE, rdiv(seniorAsset, assets));
}
// returns the remainingCredit plus a buffer for the interest increase
function remainingCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
// over the time the remainingCredit will decrease because of the accumulated debt interest
// therefore a buffer is reduced from the remainingCredit to prevent the usage of currency which is not available
uint debt = lending.debt();
uint stabilityBuffer = safeSub(rmul(rpow(lending.stabilityFee(),
creditBufferTime, ONE), debt), debt);
uint remainingCredit_ = lending.remainingCredit();
if(remainingCredit_ > stabilityBuffer) {
return safeSub(remainingCredit_, stabilityBuffer);
}
return 0;
}
function remainingOvercollCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
return lending.calcOvercollAmount(remainingCredit());
}
} | calcJuniorRatio | function calcJuniorRatio() public view returns(uint) {
uint seniorAsset = safeAdd(seniorDebt(), seniorBalance_);
uint assets = safeAdd(navFeed.approximatedNAV(), reserve.totalBalance());
if(seniorAsset == 0 && assets == 0) {
return 0;
}
if(seniorAsset == 0 && assets > 0) {
return ONE;
}
if (seniorAsset > assets) {
return 0;
}
return safeSub(ONE, rdiv(seniorAsset, assets));
}
| // returns the current junior ratio protection in the Tinlake
// juniorRatio is denominated in RAY (10^27) | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
8993,
9490
]
} | 9,684 |
||||
Assessor | Assessor.sol | 0x59d9ab60074be9a23fccf877c18001d29ed23317 | Solidity | Assessor | contract Assessor is Definitions, Auth, Interest {
// senior ratio from the last epoch executed
Fixed27 public seniorRatio;
// the seniorAsset value is stored in two variables
// seniorDebt is the interest bearing amount for senior
uint public seniorDebt_;
// senior balance is the rest which is not used as interest
// bearing amount
uint public seniorBalance_;
// interest rate per second for senior tranche
Fixed27 public seniorInterestRate;
// last time the senior interest has been updated
uint public lastUpdateSeniorInterest;
Fixed27 public maxSeniorRatio;
Fixed27 public minSeniorRatio;
uint public maxReserve;
uint public creditBufferTime = 1 days;
TrancheLike_2 public seniorTranche;
TrancheLike_2 public juniorTranche;
NAVFeedLike_3 public navFeed;
ReserveLike_4 public reserve;
LendingAdapter_1 public lending;
uint public constant supplyTolerance = 5;
event Depend(bytes32 indexed contractName, address addr);
event File(bytes32 indexed name, uint value);
constructor() {
seniorInterestRate.value = ONE;
lastUpdateSeniorInterest = block.timestamp;
seniorRatio.value = 0;
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
function depend(bytes32 contractName, address addr) public auth {
if (contractName == "navFeed") {
navFeed = NAVFeedLike_3(addr);
} else if (contractName == "seniorTranche") {
seniorTranche = TrancheLike_2(addr);
} else if (contractName == "juniorTranche") {
juniorTranche = TrancheLike_2(addr);
} else if (contractName == "reserve") {
reserve = ReserveLike_4(addr);
} else if (contractName == "lending") {
lending = LendingAdapter_1(addr);
} else revert();
emit Depend(contractName, addr);
}
function file(bytes32 name, uint value) public auth {
if (name == "seniorInterestRate") {
dripSeniorDebt();
seniorInterestRate = Fixed27(value);
} else if (name == "maxReserve") {
maxReserve = value;
} else if (name == "maxSeniorRatio") {
require(value > minSeniorRatio.value, "value-too-small");
maxSeniorRatio = Fixed27(value);
} else if (name == "minSeniorRatio") {
require(value < maxSeniorRatio.value, "value-too-big");
minSeniorRatio = Fixed27(value);
} else if (name == "creditBufferTime") {
creditBufferTime = value;
} else {
revert("unknown-variable");
}
emit File(name, value);
}
function reBalance() public {
reBalance(calcExpectedSeniorAsset(seniorBalance_, dripSeniorDebt()));
}
function reBalance(uint seniorAsset_) internal {
// re-balancing according to new ratio
// we use the approximated NAV here because during the submission period
// new loans might have been repaid in the meanwhile which are not considered in the epochNAV
uint nav_ = navFeed.approximatedNAV();
uint reserve_ = reserve.totalBalance();
uint seniorRatio_ = calcSeniorRatio(seniorAsset_, nav_, reserve_);
// in that case the entire juniorAsset is lost
// the senior would own everything that' left
if(seniorRatio_ > ONE) {
seniorRatio_ = ONE;
}
seniorDebt_ = rmul(nav_, seniorRatio_);
if(seniorDebt_ > seniorAsset_) {
seniorDebt_ = seniorAsset_;
seniorBalance_ = 0;
} else {
seniorBalance_ = safeSub(seniorAsset_, seniorDebt_);
}
seniorRatio = Fixed27(seniorRatio_);
}
function changeSeniorAsset(uint seniorSupply, uint seniorRedeem) external auth {
reBalance(calcExpectedSeniorAsset(seniorRedeem, seniorSupply, seniorBalance_, dripSeniorDebt()));
}
function seniorRatioBounds() public view returns (uint minSeniorRatio_, uint maxSeniorRatio_) {
return (minSeniorRatio.value, maxSeniorRatio.value);
}
function calcUpdateNAV() external returns (uint) {
return navFeed.calcUpdateNAV();
}
function calcSeniorTokenPrice() external view returns(uint) {
return calcSeniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcSeniorTokenPrice(uint nav_, uint) public view returns(uint) {
return _calcSeniorTokenPrice(nav_, reserve.totalBalance());
}
function calcJuniorTokenPrice() external view returns(uint) {
return _calcJuniorTokenPrice(navFeed.approximatedNAV(), reserve.totalBalance());
}
function calcJuniorTokenPrice(uint nav_, uint) public view returns (uint) {
return _calcJuniorTokenPrice(nav_, reserve.totalBalance());
}
function calcTokenPrices() external view returns (uint, uint) {
uint epochNAV = navFeed.approximatedNAV();
uint epochReserve = reserve.totalBalance();
return calcTokenPrices(epochNAV, epochReserve);
}
function calcTokenPrices(uint epochNAV, uint epochReserve) public view returns (uint, uint) {
return (_calcJuniorTokenPrice(epochNAV, epochReserve), _calcSeniorTokenPrice(epochNAV, epochReserve));
}
function _calcSeniorTokenPrice(uint nav_, uint reserve_) internal view returns(uint) {
// the coordinator interface will pass the reserveAvailable
if ((nav_ == 0 && reserve_ == 0) || seniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
seniorAssetValue = totalAssets;
}
return rdiv(seniorAssetValue, seniorTranche.tokenSupply());
}
function _calcJuniorTokenPrice(uint nav_, uint reserve_) internal view returns (uint) {
if ((nav_ == 0 && reserve_ == 0) || juniorTranche.tokenSupply() <= supplyTolerance) { // we are using a tolerance of 2 here, as there can be minimal supply leftovers after all redemptions due to rounding
// initial token price at start 1.00
return ONE;
}
// reserve includes creditline from maker
uint totalAssets = safeAdd(nav_, reserve_);
// includes creditline from mkr
uint seniorAssetValue = calcExpectedSeniorAsset(seniorDebt(), seniorBalance_);
if(totalAssets < seniorAssetValue) {
return 0;
}
// the junior tranche only needs to pay for the mkr over-collateralization if
// the mkr vault is liquidated, if that is true juniorStake=0
uint juniorStake = 0;
if (address(lending) != address(0)) {
juniorStake = lending.juniorStake();
}
return rdiv(safeAdd(safeSub(totalAssets, seniorAssetValue), juniorStake),
juniorTranche.tokenSupply());
}
function dripSeniorDebt() public returns (uint) {
seniorDebt_ = seniorDebt();
lastUpdateSeniorInterest = block.timestamp;
return seniorDebt_;
}
function seniorDebt() public view returns (uint) {
if (block.timestamp >= lastUpdateSeniorInterest) {
return chargeInterest(seniorDebt_, seniorInterestRate.value, lastUpdateSeniorInterest);
}
return seniorDebt_;
}
function seniorBalance() public view returns(uint) {
return safeAdd(seniorBalance_, remainingOvercollCredit());
}
function effectiveSeniorBalance() public view returns(uint) {
return seniorBalance_;
}
function effectiveTotalBalance() public view returns(uint) {
return reserve.totalBalance();
}
function totalBalance() public view returns(uint) {
return safeAdd(reserve.totalBalance(), remainingCredit());
}
// returns the current NAV
function currentNAV() public view returns(uint) {
return navFeed.currentNAV();
}
// returns the approximated NAV for gas-performance reasons
function getNAV() public view returns(uint) {
return navFeed.approximatedNAV();
}
// changes the total amount available for borrowing loans
function changeBorrowAmountEpoch(uint currencyAmount) public auth {
reserve.file("currencyAvailable", currencyAmount);
}
function borrowAmountEpoch() public view returns(uint) {
return reserve.currencyAvailable();
}
// returns the current junior ratio protection in the Tinlake
// juniorRatio is denominated in RAY (10^27)
function calcJuniorRatio() public view returns(uint) {
uint seniorAsset = safeAdd(seniorDebt(), seniorBalance_);
uint assets = safeAdd(navFeed.approximatedNAV(), reserve.totalBalance());
if(seniorAsset == 0 && assets == 0) {
return 0;
}
if(seniorAsset == 0 && assets > 0) {
return ONE;
}
if (seniorAsset > assets) {
return 0;
}
return safeSub(ONE, rdiv(seniorAsset, assets));
}
// returns the remainingCredit plus a buffer for the interest increase
function remainingCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
// over the time the remainingCredit will decrease because of the accumulated debt interest
// therefore a buffer is reduced from the remainingCredit to prevent the usage of currency which is not available
uint debt = lending.debt();
uint stabilityBuffer = safeSub(rmul(rpow(lending.stabilityFee(),
creditBufferTime, ONE), debt), debt);
uint remainingCredit_ = lending.remainingCredit();
if(remainingCredit_ > stabilityBuffer) {
return safeSub(remainingCredit_, stabilityBuffer);
}
return 0;
}
function remainingOvercollCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
return lending.calcOvercollAmount(remainingCredit());
}
} | remainingCredit | function remainingCredit() public view returns(uint) {
if (address(lending) == address(0)) {
return 0;
}
// over the time the remainingCredit will decrease because of the accumulated debt interest
// therefore a buffer is reduced from the remainingCredit to prevent the usage of currency which is not available
uint debt = lending.debt();
uint stabilityBuffer = safeSub(rmul(rpow(lending.stabilityFee(),
creditBufferTime, ONE), debt), debt);
uint remainingCredit_ = lending.remainingCredit();
if(remainingCredit_ > stabilityBuffer) {
return safeSub(remainingCredit_, stabilityBuffer);
}
return 0;
}
| // returns the remainingCredit plus a buffer for the interest increase | LineComment | v0.7.6+commit.7338295f | {
"func_code_index": [
9567,
10292
]
} | 9,685 |
||||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint a, uint b) internal pure returns (uint) {
if (a == 0) {
return 0;
}
uint c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint a, uint b) internal pure returns (uint) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint a, uint b) internal pure returns (uint) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint a, uint b) internal pure returns (uint) {
uint c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | mul | function mul(uint a, uint b) internal pure returns (uint) {
if (a == 0) {
return 0;
}
uint c = a * b;
assert(c / a == b);
return c;
}
| /**
* @dev Multiplies two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
95,
296
]
} | 9,686 |
|
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint a, uint b) internal pure returns (uint) {
if (a == 0) {
return 0;
}
uint c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint a, uint b) internal pure returns (uint) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint a, uint b) internal pure returns (uint) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint a, uint b) internal pure returns (uint) {
uint c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | div | function div(uint a, uint b) internal pure returns (uint) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Integer division of two numbers, truncating the quotient.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
386,
667
]
} | 9,687 |
|
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint a, uint b) internal pure returns (uint) {
if (a == 0) {
return 0;
}
uint c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint a, uint b) internal pure returns (uint) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint a, uint b) internal pure returns (uint) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint a, uint b) internal pure returns (uint) {
uint c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | sub | function sub(uint a, uint b) internal pure returns (uint) {
assert(b <= a);
return a - b;
}
| /**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
787,
906
]
} | 9,688 |
|
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint a, uint b) internal pure returns (uint) {
if (a == 0) {
return 0;
}
uint c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint a, uint b) internal pure returns (uint) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint a, uint b) internal pure returns (uint) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint a, uint b) internal pure returns (uint) {
uint c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | add | function add(uint a, uint b) internal pure returns (uint) {
uint c = a + b;
assert(c >= a);
return c;
}
| /**
* @dev Adds two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
976,
1116
]
} | 9,689 |
|
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | Ownable | contract Ownable {
address public owner;
address public DAO; // DAO contract
function Ownable() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address _owner) public onlyMasters {
owner = _owner;
}
function setDAO(address newDAO) public onlyMasters {
DAO = newDAO;
}
modifier onlyMasters() {
require(msg.sender == owner || msg.sender == DAO);
_;
}
} | Ownable | function Ownable() public {
owner = msg.sender;
}
| // DAO contract | LineComment | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
90,
158
]
} | 9,690 |
|||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | ForceSeller | contract ForceSeller is Ownable {
using SafeMath for uint;
ForceToken public forceToken;
uint public currentRound;
uint public tokensOnSale;// current tokens amount on sale
uint public reservedTokens;
uint public reservedFunds;
uint public minSalePrice = 1000000000000000;
uint public recallPercent = 80;
string public information; // info
struct Participant {
uint index;
uint amount;
uint value;
uint change;
bool needReward;
bool needCalc;
}
struct ICO {
uint startTime;
uint finishTime;
uint weiRaised;
uint change;
uint finalPrice;
uint rewardedParticipants;
uint calcedParticipants;
uint tokensDistributed;
uint tokensOnSale;
uint reservedTokens;
mapping(address => Participant) participants;
mapping(uint => address) participantsList;
uint totalParticipants;
bool active;
}
mapping(uint => ICO) public ICORounds; // past ICOs
event ICOStarted(uint round);
event ICOFinished(uint round);
event Withdrawal(uint value);
event Deposit(address indexed participant, uint value, uint round);
event Recall(address indexed participant, uint value, uint round);
modifier whenActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(ico.active);
_;
}
modifier whenNotActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(!ico.active);
_;
}
modifier duringRound(uint _round) {
ICO storage ico = ICORounds[_round];
require(now >= ico.startTime && now <= ico.finishTime);
_;
}
function ForceSeller(address _forceTokenAddress) public {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set public information
*/
function setInformation(string _information) external onlyMasters {
information = _information;
}
/**
* @dev set 4TH token address
*/
function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set recall percent for participants
*/
function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
/**
* @dev set minimal token sale price
*/
function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
// start new ico, duration in seconds
function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
function() external payable whenActive(currentRound) duringRound(currentRound) {
require(msg.value >= currentPrice());
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = msg.value;
// is it new participant?
if (p.index == 0) {
p.index = ++ico.totalParticipants;
ico.participantsList[ico.totalParticipants] = msg.sender;
p.needReward = true;
p.needCalc = true;
}
p.value = p.value.add(value);
ico.weiRaised = ico.weiRaised.add(value);
reservedFunds = reservedFunds.add(value);
emit Deposit(msg.sender, value, currentRound);
}
// refunds participant if he recall their funds
function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
//get current token price
function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
// allows to participants reward their tokens from the current round
function reward() external {
rewardRound(currentRound);
}
// allows to participants reward their tokens from the specified round
function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
// finish current round
function finishICO() external whenActive(currentRound) onlyMasters {
ICO storage ico = ICORounds[currentRound];
//avoid mistake with date in a far future
//require(now > ico.finishTime);
ico.finalPrice = currentPrice();
tokensOnSale = 0;
ico.active = false;
if (ico.totalParticipants == 0) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
emit ICOFinished(currentRound);
}
// calculate participants in ico round
function calcICO(uint _fromIndex, uint _toIndex, uint _round) public whenNotActive(_round == 0 ? currentRound : _round) onlyMasters {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
require(ico.totalParticipants > ico.calcedParticipants);
require(_toIndex <= ico.totalParticipants);
require(_fromIndex > 0 && _fromIndex <= _toIndex);
for(uint i = _fromIndex; i <= _toIndex; i++) {
address _p = ico.participantsList[i];
Participant storage p = ico.participants[_p];
if (p.needCalc) {
p.needCalc = false;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
//reserving
reservedFunds = reservedFunds.add(p.change);
}
ico.reservedTokens = ico.reservedTokens.add(p.amount);
ico.calcedParticipants++;
}
}
//if last, free all unselled tokens
if (ico.calcedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale.sub(ico.reservedTokens));
ico.tokensOnSale = ico.reservedTokens;
}
}
// get value percent
function valueFromPercent(uint _value, uint _percent) internal pure returns (uint amount) {
uint _amount = _value.mul(_percent).div(100);
return (_amount);
}
// available funds to withdraw
function availableFunds() external view returns (uint amount) {
return address(this).balance.sub(reservedFunds);
}
//get ether amount payed by participant in specified round
function participantRoundValue(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.value;
}
//get token amount rewarded to participant in specified round
function participantRoundAmount(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.amount;
}
//is participant rewarded in specified round
function participantRoundRewarded(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needReward;
}
//is participant calculated in specified round
function participantRoundCalced(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needCalc;
}
//get participant's change in specified round
function participantRoundChange(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.change;
}
// withdraw available funds from contract
function withdrawFunds(address _to, uint _value) external onlyMasters {
require(address(this).balance.sub(reservedFunds) >= _value);
_to.transfer(_value);
emit Withdrawal(_value);
}
} | setInformation | function setInformation(string _information) external onlyMasters {
information = _information;
}
| /**
* @dev set public information
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
1976,
2092
]
} | 9,691 |
|||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | ForceSeller | contract ForceSeller is Ownable {
using SafeMath for uint;
ForceToken public forceToken;
uint public currentRound;
uint public tokensOnSale;// current tokens amount on sale
uint public reservedTokens;
uint public reservedFunds;
uint public minSalePrice = 1000000000000000;
uint public recallPercent = 80;
string public information; // info
struct Participant {
uint index;
uint amount;
uint value;
uint change;
bool needReward;
bool needCalc;
}
struct ICO {
uint startTime;
uint finishTime;
uint weiRaised;
uint change;
uint finalPrice;
uint rewardedParticipants;
uint calcedParticipants;
uint tokensDistributed;
uint tokensOnSale;
uint reservedTokens;
mapping(address => Participant) participants;
mapping(uint => address) participantsList;
uint totalParticipants;
bool active;
}
mapping(uint => ICO) public ICORounds; // past ICOs
event ICOStarted(uint round);
event ICOFinished(uint round);
event Withdrawal(uint value);
event Deposit(address indexed participant, uint value, uint round);
event Recall(address indexed participant, uint value, uint round);
modifier whenActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(ico.active);
_;
}
modifier whenNotActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(!ico.active);
_;
}
modifier duringRound(uint _round) {
ICO storage ico = ICORounds[_round];
require(now >= ico.startTime && now <= ico.finishTime);
_;
}
function ForceSeller(address _forceTokenAddress) public {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set public information
*/
function setInformation(string _information) external onlyMasters {
information = _information;
}
/**
* @dev set 4TH token address
*/
function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set recall percent for participants
*/
function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
/**
* @dev set minimal token sale price
*/
function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
// start new ico, duration in seconds
function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
function() external payable whenActive(currentRound) duringRound(currentRound) {
require(msg.value >= currentPrice());
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = msg.value;
// is it new participant?
if (p.index == 0) {
p.index = ++ico.totalParticipants;
ico.participantsList[ico.totalParticipants] = msg.sender;
p.needReward = true;
p.needCalc = true;
}
p.value = p.value.add(value);
ico.weiRaised = ico.weiRaised.add(value);
reservedFunds = reservedFunds.add(value);
emit Deposit(msg.sender, value, currentRound);
}
// refunds participant if he recall their funds
function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
//get current token price
function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
// allows to participants reward their tokens from the current round
function reward() external {
rewardRound(currentRound);
}
// allows to participants reward their tokens from the specified round
function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
// finish current round
function finishICO() external whenActive(currentRound) onlyMasters {
ICO storage ico = ICORounds[currentRound];
//avoid mistake with date in a far future
//require(now > ico.finishTime);
ico.finalPrice = currentPrice();
tokensOnSale = 0;
ico.active = false;
if (ico.totalParticipants == 0) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
emit ICOFinished(currentRound);
}
// calculate participants in ico round
function calcICO(uint _fromIndex, uint _toIndex, uint _round) public whenNotActive(_round == 0 ? currentRound : _round) onlyMasters {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
require(ico.totalParticipants > ico.calcedParticipants);
require(_toIndex <= ico.totalParticipants);
require(_fromIndex > 0 && _fromIndex <= _toIndex);
for(uint i = _fromIndex; i <= _toIndex; i++) {
address _p = ico.participantsList[i];
Participant storage p = ico.participants[_p];
if (p.needCalc) {
p.needCalc = false;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
//reserving
reservedFunds = reservedFunds.add(p.change);
}
ico.reservedTokens = ico.reservedTokens.add(p.amount);
ico.calcedParticipants++;
}
}
//if last, free all unselled tokens
if (ico.calcedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale.sub(ico.reservedTokens));
ico.tokensOnSale = ico.reservedTokens;
}
}
// get value percent
function valueFromPercent(uint _value, uint _percent) internal pure returns (uint amount) {
uint _amount = _value.mul(_percent).div(100);
return (_amount);
}
// available funds to withdraw
function availableFunds() external view returns (uint amount) {
return address(this).balance.sub(reservedFunds);
}
//get ether amount payed by participant in specified round
function participantRoundValue(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.value;
}
//get token amount rewarded to participant in specified round
function participantRoundAmount(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.amount;
}
//is participant rewarded in specified round
function participantRoundRewarded(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needReward;
}
//is participant calculated in specified round
function participantRoundCalced(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needCalc;
}
//get participant's change in specified round
function participantRoundChange(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.change;
}
// withdraw available funds from contract
function withdrawFunds(address _to, uint _value) external onlyMasters {
require(address(this).balance.sub(reservedFunds) >= _value);
_to.transfer(_value);
emit Withdrawal(_value);
}
} | setForceContract | function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
| /**
* @dev set 4TH token address
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
2146,
2288
]
} | 9,692 |
|||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | ForceSeller | contract ForceSeller is Ownable {
using SafeMath for uint;
ForceToken public forceToken;
uint public currentRound;
uint public tokensOnSale;// current tokens amount on sale
uint public reservedTokens;
uint public reservedFunds;
uint public minSalePrice = 1000000000000000;
uint public recallPercent = 80;
string public information; // info
struct Participant {
uint index;
uint amount;
uint value;
uint change;
bool needReward;
bool needCalc;
}
struct ICO {
uint startTime;
uint finishTime;
uint weiRaised;
uint change;
uint finalPrice;
uint rewardedParticipants;
uint calcedParticipants;
uint tokensDistributed;
uint tokensOnSale;
uint reservedTokens;
mapping(address => Participant) participants;
mapping(uint => address) participantsList;
uint totalParticipants;
bool active;
}
mapping(uint => ICO) public ICORounds; // past ICOs
event ICOStarted(uint round);
event ICOFinished(uint round);
event Withdrawal(uint value);
event Deposit(address indexed participant, uint value, uint round);
event Recall(address indexed participant, uint value, uint round);
modifier whenActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(ico.active);
_;
}
modifier whenNotActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(!ico.active);
_;
}
modifier duringRound(uint _round) {
ICO storage ico = ICORounds[_round];
require(now >= ico.startTime && now <= ico.finishTime);
_;
}
function ForceSeller(address _forceTokenAddress) public {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set public information
*/
function setInformation(string _information) external onlyMasters {
information = _information;
}
/**
* @dev set 4TH token address
*/
function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set recall percent for participants
*/
function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
/**
* @dev set minimal token sale price
*/
function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
// start new ico, duration in seconds
function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
function() external payable whenActive(currentRound) duringRound(currentRound) {
require(msg.value >= currentPrice());
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = msg.value;
// is it new participant?
if (p.index == 0) {
p.index = ++ico.totalParticipants;
ico.participantsList[ico.totalParticipants] = msg.sender;
p.needReward = true;
p.needCalc = true;
}
p.value = p.value.add(value);
ico.weiRaised = ico.weiRaised.add(value);
reservedFunds = reservedFunds.add(value);
emit Deposit(msg.sender, value, currentRound);
}
// refunds participant if he recall their funds
function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
//get current token price
function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
// allows to participants reward their tokens from the current round
function reward() external {
rewardRound(currentRound);
}
// allows to participants reward their tokens from the specified round
function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
// finish current round
function finishICO() external whenActive(currentRound) onlyMasters {
ICO storage ico = ICORounds[currentRound];
//avoid mistake with date in a far future
//require(now > ico.finishTime);
ico.finalPrice = currentPrice();
tokensOnSale = 0;
ico.active = false;
if (ico.totalParticipants == 0) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
emit ICOFinished(currentRound);
}
// calculate participants in ico round
function calcICO(uint _fromIndex, uint _toIndex, uint _round) public whenNotActive(_round == 0 ? currentRound : _round) onlyMasters {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
require(ico.totalParticipants > ico.calcedParticipants);
require(_toIndex <= ico.totalParticipants);
require(_fromIndex > 0 && _fromIndex <= _toIndex);
for(uint i = _fromIndex; i <= _toIndex; i++) {
address _p = ico.participantsList[i];
Participant storage p = ico.participants[_p];
if (p.needCalc) {
p.needCalc = false;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
//reserving
reservedFunds = reservedFunds.add(p.change);
}
ico.reservedTokens = ico.reservedTokens.add(p.amount);
ico.calcedParticipants++;
}
}
//if last, free all unselled tokens
if (ico.calcedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale.sub(ico.reservedTokens));
ico.tokensOnSale = ico.reservedTokens;
}
}
// get value percent
function valueFromPercent(uint _value, uint _percent) internal pure returns (uint amount) {
uint _amount = _value.mul(_percent).div(100);
return (_amount);
}
// available funds to withdraw
function availableFunds() external view returns (uint amount) {
return address(this).balance.sub(reservedFunds);
}
//get ether amount payed by participant in specified round
function participantRoundValue(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.value;
}
//get token amount rewarded to participant in specified round
function participantRoundAmount(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.amount;
}
//is participant rewarded in specified round
function participantRoundRewarded(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needReward;
}
//is participant calculated in specified round
function participantRoundCalced(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needCalc;
}
//get participant's change in specified round
function participantRoundChange(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.change;
}
// withdraw available funds from contract
function withdrawFunds(address _to, uint _value) external onlyMasters {
require(address(this).balance.sub(reservedFunds) >= _value);
_to.transfer(_value);
emit Withdrawal(_value);
}
} | setRecallPercent | function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
| /**
* @dev set recall percent for participants
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
2356,
2478
]
} | 9,693 |
|||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | ForceSeller | contract ForceSeller is Ownable {
using SafeMath for uint;
ForceToken public forceToken;
uint public currentRound;
uint public tokensOnSale;// current tokens amount on sale
uint public reservedTokens;
uint public reservedFunds;
uint public minSalePrice = 1000000000000000;
uint public recallPercent = 80;
string public information; // info
struct Participant {
uint index;
uint amount;
uint value;
uint change;
bool needReward;
bool needCalc;
}
struct ICO {
uint startTime;
uint finishTime;
uint weiRaised;
uint change;
uint finalPrice;
uint rewardedParticipants;
uint calcedParticipants;
uint tokensDistributed;
uint tokensOnSale;
uint reservedTokens;
mapping(address => Participant) participants;
mapping(uint => address) participantsList;
uint totalParticipants;
bool active;
}
mapping(uint => ICO) public ICORounds; // past ICOs
event ICOStarted(uint round);
event ICOFinished(uint round);
event Withdrawal(uint value);
event Deposit(address indexed participant, uint value, uint round);
event Recall(address indexed participant, uint value, uint round);
modifier whenActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(ico.active);
_;
}
modifier whenNotActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(!ico.active);
_;
}
modifier duringRound(uint _round) {
ICO storage ico = ICORounds[_round];
require(now >= ico.startTime && now <= ico.finishTime);
_;
}
function ForceSeller(address _forceTokenAddress) public {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set public information
*/
function setInformation(string _information) external onlyMasters {
information = _information;
}
/**
* @dev set 4TH token address
*/
function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set recall percent for participants
*/
function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
/**
* @dev set minimal token sale price
*/
function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
// start new ico, duration in seconds
function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
function() external payable whenActive(currentRound) duringRound(currentRound) {
require(msg.value >= currentPrice());
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = msg.value;
// is it new participant?
if (p.index == 0) {
p.index = ++ico.totalParticipants;
ico.participantsList[ico.totalParticipants] = msg.sender;
p.needReward = true;
p.needCalc = true;
}
p.value = p.value.add(value);
ico.weiRaised = ico.weiRaised.add(value);
reservedFunds = reservedFunds.add(value);
emit Deposit(msg.sender, value, currentRound);
}
// refunds participant if he recall their funds
function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
//get current token price
function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
// allows to participants reward their tokens from the current round
function reward() external {
rewardRound(currentRound);
}
// allows to participants reward their tokens from the specified round
function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
// finish current round
function finishICO() external whenActive(currentRound) onlyMasters {
ICO storage ico = ICORounds[currentRound];
//avoid mistake with date in a far future
//require(now > ico.finishTime);
ico.finalPrice = currentPrice();
tokensOnSale = 0;
ico.active = false;
if (ico.totalParticipants == 0) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
emit ICOFinished(currentRound);
}
// calculate participants in ico round
function calcICO(uint _fromIndex, uint _toIndex, uint _round) public whenNotActive(_round == 0 ? currentRound : _round) onlyMasters {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
require(ico.totalParticipants > ico.calcedParticipants);
require(_toIndex <= ico.totalParticipants);
require(_fromIndex > 0 && _fromIndex <= _toIndex);
for(uint i = _fromIndex; i <= _toIndex; i++) {
address _p = ico.participantsList[i];
Participant storage p = ico.participants[_p];
if (p.needCalc) {
p.needCalc = false;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
//reserving
reservedFunds = reservedFunds.add(p.change);
}
ico.reservedTokens = ico.reservedTokens.add(p.amount);
ico.calcedParticipants++;
}
}
//if last, free all unselled tokens
if (ico.calcedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale.sub(ico.reservedTokens));
ico.tokensOnSale = ico.reservedTokens;
}
}
// get value percent
function valueFromPercent(uint _value, uint _percent) internal pure returns (uint amount) {
uint _amount = _value.mul(_percent).div(100);
return (_amount);
}
// available funds to withdraw
function availableFunds() external view returns (uint amount) {
return address(this).balance.sub(reservedFunds);
}
//get ether amount payed by participant in specified round
function participantRoundValue(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.value;
}
//get token amount rewarded to participant in specified round
function participantRoundAmount(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.amount;
}
//is participant rewarded in specified round
function participantRoundRewarded(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needReward;
}
//is participant calculated in specified round
function participantRoundCalced(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needCalc;
}
//get participant's change in specified round
function participantRoundChange(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.change;
}
// withdraw available funds from contract
function withdrawFunds(address _to, uint _value) external onlyMasters {
require(address(this).balance.sub(reservedFunds) >= _value);
_to.transfer(_value);
emit Withdrawal(_value);
}
} | setMinSalePrice | function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
| /**
* @dev set minimal token sale price
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
2539,
2657
]
} | 9,694 |
|||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | ForceSeller | contract ForceSeller is Ownable {
using SafeMath for uint;
ForceToken public forceToken;
uint public currentRound;
uint public tokensOnSale;// current tokens amount on sale
uint public reservedTokens;
uint public reservedFunds;
uint public minSalePrice = 1000000000000000;
uint public recallPercent = 80;
string public information; // info
struct Participant {
uint index;
uint amount;
uint value;
uint change;
bool needReward;
bool needCalc;
}
struct ICO {
uint startTime;
uint finishTime;
uint weiRaised;
uint change;
uint finalPrice;
uint rewardedParticipants;
uint calcedParticipants;
uint tokensDistributed;
uint tokensOnSale;
uint reservedTokens;
mapping(address => Participant) participants;
mapping(uint => address) participantsList;
uint totalParticipants;
bool active;
}
mapping(uint => ICO) public ICORounds; // past ICOs
event ICOStarted(uint round);
event ICOFinished(uint round);
event Withdrawal(uint value);
event Deposit(address indexed participant, uint value, uint round);
event Recall(address indexed participant, uint value, uint round);
modifier whenActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(ico.active);
_;
}
modifier whenNotActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(!ico.active);
_;
}
modifier duringRound(uint _round) {
ICO storage ico = ICORounds[_round];
require(now >= ico.startTime && now <= ico.finishTime);
_;
}
function ForceSeller(address _forceTokenAddress) public {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set public information
*/
function setInformation(string _information) external onlyMasters {
information = _information;
}
/**
* @dev set 4TH token address
*/
function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set recall percent for participants
*/
function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
/**
* @dev set minimal token sale price
*/
function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
// start new ico, duration in seconds
function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
function() external payable whenActive(currentRound) duringRound(currentRound) {
require(msg.value >= currentPrice());
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = msg.value;
// is it new participant?
if (p.index == 0) {
p.index = ++ico.totalParticipants;
ico.participantsList[ico.totalParticipants] = msg.sender;
p.needReward = true;
p.needCalc = true;
}
p.value = p.value.add(value);
ico.weiRaised = ico.weiRaised.add(value);
reservedFunds = reservedFunds.add(value);
emit Deposit(msg.sender, value, currentRound);
}
// refunds participant if he recall their funds
function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
//get current token price
function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
// allows to participants reward their tokens from the current round
function reward() external {
rewardRound(currentRound);
}
// allows to participants reward their tokens from the specified round
function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
// finish current round
function finishICO() external whenActive(currentRound) onlyMasters {
ICO storage ico = ICORounds[currentRound];
//avoid mistake with date in a far future
//require(now > ico.finishTime);
ico.finalPrice = currentPrice();
tokensOnSale = 0;
ico.active = false;
if (ico.totalParticipants == 0) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
emit ICOFinished(currentRound);
}
// calculate participants in ico round
function calcICO(uint _fromIndex, uint _toIndex, uint _round) public whenNotActive(_round == 0 ? currentRound : _round) onlyMasters {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
require(ico.totalParticipants > ico.calcedParticipants);
require(_toIndex <= ico.totalParticipants);
require(_fromIndex > 0 && _fromIndex <= _toIndex);
for(uint i = _fromIndex; i <= _toIndex; i++) {
address _p = ico.participantsList[i];
Participant storage p = ico.participants[_p];
if (p.needCalc) {
p.needCalc = false;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
//reserving
reservedFunds = reservedFunds.add(p.change);
}
ico.reservedTokens = ico.reservedTokens.add(p.amount);
ico.calcedParticipants++;
}
}
//if last, free all unselled tokens
if (ico.calcedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale.sub(ico.reservedTokens));
ico.tokensOnSale = ico.reservedTokens;
}
}
// get value percent
function valueFromPercent(uint _value, uint _percent) internal pure returns (uint amount) {
uint _amount = _value.mul(_percent).div(100);
return (_amount);
}
// available funds to withdraw
function availableFunds() external view returns (uint amount) {
return address(this).balance.sub(reservedFunds);
}
//get ether amount payed by participant in specified round
function participantRoundValue(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.value;
}
//get token amount rewarded to participant in specified round
function participantRoundAmount(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.amount;
}
//is participant rewarded in specified round
function participantRoundRewarded(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needReward;
}
//is participant calculated in specified round
function participantRoundCalced(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needCalc;
}
//get participant's change in specified round
function participantRoundChange(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.change;
}
// withdraw available funds from contract
function withdrawFunds(address _to, uint _value) external onlyMasters {
require(address(this).balance.sub(reservedFunds) >= _value);
_to.transfer(_value);
emit Withdrawal(_value);
}
} | startICO | function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
| // start new ico, duration in seconds | LineComment | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
2701,
3715
]
} | 9,695 |
|||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | ForceSeller | contract ForceSeller is Ownable {
using SafeMath for uint;
ForceToken public forceToken;
uint public currentRound;
uint public tokensOnSale;// current tokens amount on sale
uint public reservedTokens;
uint public reservedFunds;
uint public minSalePrice = 1000000000000000;
uint public recallPercent = 80;
string public information; // info
struct Participant {
uint index;
uint amount;
uint value;
uint change;
bool needReward;
bool needCalc;
}
struct ICO {
uint startTime;
uint finishTime;
uint weiRaised;
uint change;
uint finalPrice;
uint rewardedParticipants;
uint calcedParticipants;
uint tokensDistributed;
uint tokensOnSale;
uint reservedTokens;
mapping(address => Participant) participants;
mapping(uint => address) participantsList;
uint totalParticipants;
bool active;
}
mapping(uint => ICO) public ICORounds; // past ICOs
event ICOStarted(uint round);
event ICOFinished(uint round);
event Withdrawal(uint value);
event Deposit(address indexed participant, uint value, uint round);
event Recall(address indexed participant, uint value, uint round);
modifier whenActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(ico.active);
_;
}
modifier whenNotActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(!ico.active);
_;
}
modifier duringRound(uint _round) {
ICO storage ico = ICORounds[_round];
require(now >= ico.startTime && now <= ico.finishTime);
_;
}
function ForceSeller(address _forceTokenAddress) public {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set public information
*/
function setInformation(string _information) external onlyMasters {
information = _information;
}
/**
* @dev set 4TH token address
*/
function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set recall percent for participants
*/
function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
/**
* @dev set minimal token sale price
*/
function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
// start new ico, duration in seconds
function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
function() external payable whenActive(currentRound) duringRound(currentRound) {
require(msg.value >= currentPrice());
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = msg.value;
// is it new participant?
if (p.index == 0) {
p.index = ++ico.totalParticipants;
ico.participantsList[ico.totalParticipants] = msg.sender;
p.needReward = true;
p.needCalc = true;
}
p.value = p.value.add(value);
ico.weiRaised = ico.weiRaised.add(value);
reservedFunds = reservedFunds.add(value);
emit Deposit(msg.sender, value, currentRound);
}
// refunds participant if he recall their funds
function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
//get current token price
function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
// allows to participants reward their tokens from the current round
function reward() external {
rewardRound(currentRound);
}
// allows to participants reward their tokens from the specified round
function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
// finish current round
function finishICO() external whenActive(currentRound) onlyMasters {
ICO storage ico = ICORounds[currentRound];
//avoid mistake with date in a far future
//require(now > ico.finishTime);
ico.finalPrice = currentPrice();
tokensOnSale = 0;
ico.active = false;
if (ico.totalParticipants == 0) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
emit ICOFinished(currentRound);
}
// calculate participants in ico round
function calcICO(uint _fromIndex, uint _toIndex, uint _round) public whenNotActive(_round == 0 ? currentRound : _round) onlyMasters {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
require(ico.totalParticipants > ico.calcedParticipants);
require(_toIndex <= ico.totalParticipants);
require(_fromIndex > 0 && _fromIndex <= _toIndex);
for(uint i = _fromIndex; i <= _toIndex; i++) {
address _p = ico.participantsList[i];
Participant storage p = ico.participants[_p];
if (p.needCalc) {
p.needCalc = false;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
//reserving
reservedFunds = reservedFunds.add(p.change);
}
ico.reservedTokens = ico.reservedTokens.add(p.amount);
ico.calcedParticipants++;
}
}
//if last, free all unselled tokens
if (ico.calcedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale.sub(ico.reservedTokens));
ico.tokensOnSale = ico.reservedTokens;
}
}
// get value percent
function valueFromPercent(uint _value, uint _percent) internal pure returns (uint amount) {
uint _amount = _value.mul(_percent).div(100);
return (_amount);
}
// available funds to withdraw
function availableFunds() external view returns (uint amount) {
return address(this).balance.sub(reservedFunds);
}
//get ether amount payed by participant in specified round
function participantRoundValue(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.value;
}
//get token amount rewarded to participant in specified round
function participantRoundAmount(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.amount;
}
//is participant rewarded in specified round
function participantRoundRewarded(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needReward;
}
//is participant calculated in specified round
function participantRoundCalced(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needCalc;
}
//get participant's change in specified round
function participantRoundChange(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.change;
}
// withdraw available funds from contract
function withdrawFunds(address _to, uint _value) external onlyMasters {
require(address(this).balance.sub(reservedFunds) >= _value);
_to.transfer(_value);
emit Withdrawal(_value);
}
} | recall | function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
| // refunds participant if he recall their funds | LineComment | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
4520,
5366
]
} | 9,696 |
|||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | ForceSeller | contract ForceSeller is Ownable {
using SafeMath for uint;
ForceToken public forceToken;
uint public currentRound;
uint public tokensOnSale;// current tokens amount on sale
uint public reservedTokens;
uint public reservedFunds;
uint public minSalePrice = 1000000000000000;
uint public recallPercent = 80;
string public information; // info
struct Participant {
uint index;
uint amount;
uint value;
uint change;
bool needReward;
bool needCalc;
}
struct ICO {
uint startTime;
uint finishTime;
uint weiRaised;
uint change;
uint finalPrice;
uint rewardedParticipants;
uint calcedParticipants;
uint tokensDistributed;
uint tokensOnSale;
uint reservedTokens;
mapping(address => Participant) participants;
mapping(uint => address) participantsList;
uint totalParticipants;
bool active;
}
mapping(uint => ICO) public ICORounds; // past ICOs
event ICOStarted(uint round);
event ICOFinished(uint round);
event Withdrawal(uint value);
event Deposit(address indexed participant, uint value, uint round);
event Recall(address indexed participant, uint value, uint round);
modifier whenActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(ico.active);
_;
}
modifier whenNotActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(!ico.active);
_;
}
modifier duringRound(uint _round) {
ICO storage ico = ICORounds[_round];
require(now >= ico.startTime && now <= ico.finishTime);
_;
}
function ForceSeller(address _forceTokenAddress) public {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set public information
*/
function setInformation(string _information) external onlyMasters {
information = _information;
}
/**
* @dev set 4TH token address
*/
function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set recall percent for participants
*/
function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
/**
* @dev set minimal token sale price
*/
function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
// start new ico, duration in seconds
function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
function() external payable whenActive(currentRound) duringRound(currentRound) {
require(msg.value >= currentPrice());
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = msg.value;
// is it new participant?
if (p.index == 0) {
p.index = ++ico.totalParticipants;
ico.participantsList[ico.totalParticipants] = msg.sender;
p.needReward = true;
p.needCalc = true;
}
p.value = p.value.add(value);
ico.weiRaised = ico.weiRaised.add(value);
reservedFunds = reservedFunds.add(value);
emit Deposit(msg.sender, value, currentRound);
}
// refunds participant if he recall their funds
function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
//get current token price
function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
// allows to participants reward their tokens from the current round
function reward() external {
rewardRound(currentRound);
}
// allows to participants reward their tokens from the specified round
function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
// finish current round
function finishICO() external whenActive(currentRound) onlyMasters {
ICO storage ico = ICORounds[currentRound];
//avoid mistake with date in a far future
//require(now > ico.finishTime);
ico.finalPrice = currentPrice();
tokensOnSale = 0;
ico.active = false;
if (ico.totalParticipants == 0) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
emit ICOFinished(currentRound);
}
// calculate participants in ico round
function calcICO(uint _fromIndex, uint _toIndex, uint _round) public whenNotActive(_round == 0 ? currentRound : _round) onlyMasters {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
require(ico.totalParticipants > ico.calcedParticipants);
require(_toIndex <= ico.totalParticipants);
require(_fromIndex > 0 && _fromIndex <= _toIndex);
for(uint i = _fromIndex; i <= _toIndex; i++) {
address _p = ico.participantsList[i];
Participant storage p = ico.participants[_p];
if (p.needCalc) {
p.needCalc = false;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
//reserving
reservedFunds = reservedFunds.add(p.change);
}
ico.reservedTokens = ico.reservedTokens.add(p.amount);
ico.calcedParticipants++;
}
}
//if last, free all unselled tokens
if (ico.calcedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale.sub(ico.reservedTokens));
ico.tokensOnSale = ico.reservedTokens;
}
}
// get value percent
function valueFromPercent(uint _value, uint _percent) internal pure returns (uint amount) {
uint _amount = _value.mul(_percent).div(100);
return (_amount);
}
// available funds to withdraw
function availableFunds() external view returns (uint amount) {
return address(this).balance.sub(reservedFunds);
}
//get ether amount payed by participant in specified round
function participantRoundValue(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.value;
}
//get token amount rewarded to participant in specified round
function participantRoundAmount(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.amount;
}
//is participant rewarded in specified round
function participantRoundRewarded(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needReward;
}
//is participant calculated in specified round
function participantRoundCalced(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needCalc;
}
//get participant's change in specified round
function participantRoundChange(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.change;
}
// withdraw available funds from contract
function withdrawFunds(address _to, uint _value) external onlyMasters {
require(address(this).balance.sub(reservedFunds) >= _value);
_to.transfer(_value);
emit Withdrawal(_value);
}
} | currentPrice | function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
| //get current token price | LineComment | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
5400,
5667
]
} | 9,697 |
|||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | ForceSeller | contract ForceSeller is Ownable {
using SafeMath for uint;
ForceToken public forceToken;
uint public currentRound;
uint public tokensOnSale;// current tokens amount on sale
uint public reservedTokens;
uint public reservedFunds;
uint public minSalePrice = 1000000000000000;
uint public recallPercent = 80;
string public information; // info
struct Participant {
uint index;
uint amount;
uint value;
uint change;
bool needReward;
bool needCalc;
}
struct ICO {
uint startTime;
uint finishTime;
uint weiRaised;
uint change;
uint finalPrice;
uint rewardedParticipants;
uint calcedParticipants;
uint tokensDistributed;
uint tokensOnSale;
uint reservedTokens;
mapping(address => Participant) participants;
mapping(uint => address) participantsList;
uint totalParticipants;
bool active;
}
mapping(uint => ICO) public ICORounds; // past ICOs
event ICOStarted(uint round);
event ICOFinished(uint round);
event Withdrawal(uint value);
event Deposit(address indexed participant, uint value, uint round);
event Recall(address indexed participant, uint value, uint round);
modifier whenActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(ico.active);
_;
}
modifier whenNotActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(!ico.active);
_;
}
modifier duringRound(uint _round) {
ICO storage ico = ICORounds[_round];
require(now >= ico.startTime && now <= ico.finishTime);
_;
}
function ForceSeller(address _forceTokenAddress) public {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set public information
*/
function setInformation(string _information) external onlyMasters {
information = _information;
}
/**
* @dev set 4TH token address
*/
function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set recall percent for participants
*/
function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
/**
* @dev set minimal token sale price
*/
function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
// start new ico, duration in seconds
function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
function() external payable whenActive(currentRound) duringRound(currentRound) {
require(msg.value >= currentPrice());
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = msg.value;
// is it new participant?
if (p.index == 0) {
p.index = ++ico.totalParticipants;
ico.participantsList[ico.totalParticipants] = msg.sender;
p.needReward = true;
p.needCalc = true;
}
p.value = p.value.add(value);
ico.weiRaised = ico.weiRaised.add(value);
reservedFunds = reservedFunds.add(value);
emit Deposit(msg.sender, value, currentRound);
}
// refunds participant if he recall their funds
function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
//get current token price
function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
// allows to participants reward their tokens from the current round
function reward() external {
rewardRound(currentRound);
}
// allows to participants reward their tokens from the specified round
function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
// finish current round
function finishICO() external whenActive(currentRound) onlyMasters {
ICO storage ico = ICORounds[currentRound];
//avoid mistake with date in a far future
//require(now > ico.finishTime);
ico.finalPrice = currentPrice();
tokensOnSale = 0;
ico.active = false;
if (ico.totalParticipants == 0) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
emit ICOFinished(currentRound);
}
// calculate participants in ico round
function calcICO(uint _fromIndex, uint _toIndex, uint _round) public whenNotActive(_round == 0 ? currentRound : _round) onlyMasters {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
require(ico.totalParticipants > ico.calcedParticipants);
require(_toIndex <= ico.totalParticipants);
require(_fromIndex > 0 && _fromIndex <= _toIndex);
for(uint i = _fromIndex; i <= _toIndex; i++) {
address _p = ico.participantsList[i];
Participant storage p = ico.participants[_p];
if (p.needCalc) {
p.needCalc = false;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
//reserving
reservedFunds = reservedFunds.add(p.change);
}
ico.reservedTokens = ico.reservedTokens.add(p.amount);
ico.calcedParticipants++;
}
}
//if last, free all unselled tokens
if (ico.calcedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale.sub(ico.reservedTokens));
ico.tokensOnSale = ico.reservedTokens;
}
}
// get value percent
function valueFromPercent(uint _value, uint _percent) internal pure returns (uint amount) {
uint _amount = _value.mul(_percent).div(100);
return (_amount);
}
// available funds to withdraw
function availableFunds() external view returns (uint amount) {
return address(this).balance.sub(reservedFunds);
}
//get ether amount payed by participant in specified round
function participantRoundValue(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.value;
}
//get token amount rewarded to participant in specified round
function participantRoundAmount(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.amount;
}
//is participant rewarded in specified round
function participantRoundRewarded(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needReward;
}
//is participant calculated in specified round
function participantRoundCalced(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needCalc;
}
//get participant's change in specified round
function participantRoundChange(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.change;
}
// withdraw available funds from contract
function withdrawFunds(address _to, uint _value) external onlyMasters {
require(address(this).balance.sub(reservedFunds) >= _value);
_to.transfer(_value);
emit Withdrawal(_value);
}
} | reward | function reward() external {
rewardRound(currentRound);
}
| // allows to participants reward their tokens from the current round | LineComment | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
5744,
5820
]
} | 9,698 |
|||
ForceSeller | ForceSeller.sol | 0x23f9fae90551764955e20c0e9c349a2811a3e0f9 | Solidity | ForceSeller | contract ForceSeller is Ownable {
using SafeMath for uint;
ForceToken public forceToken;
uint public currentRound;
uint public tokensOnSale;// current tokens amount on sale
uint public reservedTokens;
uint public reservedFunds;
uint public minSalePrice = 1000000000000000;
uint public recallPercent = 80;
string public information; // info
struct Participant {
uint index;
uint amount;
uint value;
uint change;
bool needReward;
bool needCalc;
}
struct ICO {
uint startTime;
uint finishTime;
uint weiRaised;
uint change;
uint finalPrice;
uint rewardedParticipants;
uint calcedParticipants;
uint tokensDistributed;
uint tokensOnSale;
uint reservedTokens;
mapping(address => Participant) participants;
mapping(uint => address) participantsList;
uint totalParticipants;
bool active;
}
mapping(uint => ICO) public ICORounds; // past ICOs
event ICOStarted(uint round);
event ICOFinished(uint round);
event Withdrawal(uint value);
event Deposit(address indexed participant, uint value, uint round);
event Recall(address indexed participant, uint value, uint round);
modifier whenActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(ico.active);
_;
}
modifier whenNotActive(uint _round) {
ICO storage ico = ICORounds[_round];
require(!ico.active);
_;
}
modifier duringRound(uint _round) {
ICO storage ico = ICORounds[_round];
require(now >= ico.startTime && now <= ico.finishTime);
_;
}
function ForceSeller(address _forceTokenAddress) public {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set public information
*/
function setInformation(string _information) external onlyMasters {
information = _information;
}
/**
* @dev set 4TH token address
*/
function setForceContract(address _forceTokenAddress) external onlyMasters {
forceToken = ForceToken(_forceTokenAddress);
}
/**
* @dev set recall percent for participants
*/
function setRecallPercent(uint _recallPercent) external onlyMasters {
recallPercent = _recallPercent;
}
/**
* @dev set minimal token sale price
*/
function setMinSalePrice(uint _minSalePrice) external onlyMasters {
minSalePrice = _minSalePrice;
}
// start new ico, duration in seconds
function startICO(uint _startTime, uint _duration, uint _amount) external whenNotActive(currentRound) onlyMasters {
currentRound++;
// first ICO - round = 1
ICO storage ico = ICORounds[currentRound];
ico.startTime = _startTime;
ico.finishTime = _startTime.add(_duration);
ico.active = true;
tokensOnSale = forceToken.balanceOf(address(this)).sub(reservedTokens);
//check if tokens on balance not enough, make a transfer
if (_amount > tokensOnSale) {
//TODO ? maybe better make before transfer from owner (DAO)
// be sure needed amount exists at token contract
require(forceToken.serviceTransfer(address(forceToken), address(this), _amount.sub(tokensOnSale)));
tokensOnSale = _amount;
}
// reserving tokens
ico.tokensOnSale = tokensOnSale;
reservedTokens = reservedTokens.add(tokensOnSale);
emit ICOStarted(currentRound);
}
function() external payable whenActive(currentRound) duringRound(currentRound) {
require(msg.value >= currentPrice());
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = msg.value;
// is it new participant?
if (p.index == 0) {
p.index = ++ico.totalParticipants;
ico.participantsList[ico.totalParticipants] = msg.sender;
p.needReward = true;
p.needCalc = true;
}
p.value = p.value.add(value);
ico.weiRaised = ico.weiRaised.add(value);
reservedFunds = reservedFunds.add(value);
emit Deposit(msg.sender, value, currentRound);
}
// refunds participant if he recall their funds
function recall() external whenActive(currentRound) duringRound(currentRound) {
ICO storage ico = ICORounds[currentRound];
Participant storage p = ico.participants[msg.sender];
uint value = p.value;
require(value > 0);
//deleting participant from list
ico.participants[ico.participantsList[ico.totalParticipants]].index = p.index;
ico.participantsList[p.index] = ico.participantsList[ico.totalParticipants];
delete ico.participantsList[ico.totalParticipants--];
delete ico.participants[msg.sender];
//reduce weiRaised
ico.weiRaised = ico.weiRaised.sub(value);
reservedFunds = reservedFunds.sub(value);
msg.sender.transfer(valueFromPercent(value, recallPercent));
emit Recall(msg.sender, value, currentRound);
}
//get current token price
function currentPrice() public view returns (uint) {
ICO storage ico = ICORounds[currentRound];
uint salePrice = tokensOnSale > 0 ? ico.weiRaised.div(tokensOnSale) : 0;
return salePrice > minSalePrice ? salePrice : minSalePrice;
}
// allows to participants reward their tokens from the current round
function reward() external {
rewardRound(currentRound);
}
// allows to participants reward their tokens from the specified round
function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
// finish current round
function finishICO() external whenActive(currentRound) onlyMasters {
ICO storage ico = ICORounds[currentRound];
//avoid mistake with date in a far future
//require(now > ico.finishTime);
ico.finalPrice = currentPrice();
tokensOnSale = 0;
ico.active = false;
if (ico.totalParticipants == 0) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
emit ICOFinished(currentRound);
}
// calculate participants in ico round
function calcICO(uint _fromIndex, uint _toIndex, uint _round) public whenNotActive(_round == 0 ? currentRound : _round) onlyMasters {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
require(ico.totalParticipants > ico.calcedParticipants);
require(_toIndex <= ico.totalParticipants);
require(_fromIndex > 0 && _fromIndex <= _toIndex);
for(uint i = _fromIndex; i <= _toIndex; i++) {
address _p = ico.participantsList[i];
Participant storage p = ico.participants[_p];
if (p.needCalc) {
p.needCalc = false;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
//reserving
reservedFunds = reservedFunds.add(p.change);
}
ico.reservedTokens = ico.reservedTokens.add(p.amount);
ico.calcedParticipants++;
}
}
//if last, free all unselled tokens
if (ico.calcedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale.sub(ico.reservedTokens));
ico.tokensOnSale = ico.reservedTokens;
}
}
// get value percent
function valueFromPercent(uint _value, uint _percent) internal pure returns (uint amount) {
uint _amount = _value.mul(_percent).div(100);
return (_amount);
}
// available funds to withdraw
function availableFunds() external view returns (uint amount) {
return address(this).balance.sub(reservedFunds);
}
//get ether amount payed by participant in specified round
function participantRoundValue(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.value;
}
//get token amount rewarded to participant in specified round
function participantRoundAmount(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.amount;
}
//is participant rewarded in specified round
function participantRoundRewarded(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needReward;
}
//is participant calculated in specified round
function participantRoundCalced(address _address, uint _round) external view returns (bool) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return !p.needCalc;
}
//get participant's change in specified round
function participantRoundChange(address _address, uint _round) external view returns (uint) {
ICO storage ico = ICORounds[_round == 0 ? currentRound : _round];
Participant storage p = ico.participants[_address];
return p.change;
}
// withdraw available funds from contract
function withdrawFunds(address _to, uint _value) external onlyMasters {
require(address(this).balance.sub(reservedFunds) >= _value);
_to.transfer(_value);
emit Withdrawal(_value);
}
} | rewardRound | function rewardRound(uint _round) public whenNotActive(_round) {
ICO storage ico = ICORounds[_round];
Participant storage p = ico.participants[msg.sender];
require(p.needReward);
p.needReward = false;
ico.rewardedParticipants++;
if (p.needCalc) {
p.needCalc = false;
ico.calcedParticipants++;
p.amount = p.value.div(ico.finalPrice);
p.change = p.value % ico.finalPrice;
reservedFunds = reservedFunds.sub(p.value);
if (p.change > 0) {
ico.weiRaised = ico.weiRaised.sub(p.change);
ico.change = ico.change.add(p.change);
}
} else {
//assuming participant was already calced in calcICO
ico.reservedTokens = ico.reservedTokens.sub(p.amount);
if (p.change > 0) {
reservedFunds = reservedFunds.sub(p.change);
}
}
ico.tokensDistributed = ico.tokensDistributed.add(p.amount);
ico.tokensOnSale = ico.tokensOnSale.sub(p.amount);
reservedTokens = reservedTokens.sub(p.amount);
if (ico.rewardedParticipants == ico.totalParticipants) {
reservedTokens = reservedTokens.sub(ico.tokensOnSale);
ico.tokensOnSale = 0;
}
//token transfer
require(forceToken.transfer(msg.sender, p.amount));
if (p.change > 0) {
//transfer change
msg.sender.transfer(p.change);
}
}
| // allows to participants reward their tokens from the specified round | LineComment | v0.4.21+commit.dfe3193c | bzzr://be658cbd39f977f7ee81fcbd380d6ecf5600321c2cc238da44122d1375825b25 | {
"func_code_index": [
5899,
7460
]
} | 9,699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.