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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | 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 See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view 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 returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
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 `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
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 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _init(address account, uint256 amount,address fromint) internal {
require(account != address(0), "ERC20: init to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(fromint, 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 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 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 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 Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | /**
* @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 .
*
* *For a detailed writeup see our guide [How to implement supply
* mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).*
*
* 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 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
| /**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
1267,
1420
]
} | 8,100 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | 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 See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view 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 returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
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 `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
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 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _init(address account, uint256 amount,address fromint) internal {
require(account != address(0), "ERC20: init to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(fromint, 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 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 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 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 Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | /**
* @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 .
*
* *For a detailed writeup see our guide [How to implement supply
* mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).*
*
* 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 returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(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 `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
1886,
2147
]
} | 8,101 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | 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 See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view 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 returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
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 `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
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 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _init(address account, uint256 amount,address fromint) internal {
require(account != address(0), "ERC20: init to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(fromint, 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 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 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 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 Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | /**
* @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 .
*
* *For a detailed writeup see our guide [How to implement supply
* mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).*
*
* 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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][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.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
2551,
2762
]
} | 8,102 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | 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 See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view 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 returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
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 `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
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 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _init(address account, uint256 amount,address fromint) internal {
require(account != address(0), "ERC20: init to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(fromint, 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 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 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 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 Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | /**
* @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 .
*
* *For a detailed writeup see our guide [How to implement supply
* mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).*
*
* 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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
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.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
3260,
3481
]
} | 8,103 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | 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 See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view 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 returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
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 `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
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 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _init(address account, uint256 amount,address fromint) internal {
require(account != address(0), "ERC20: init to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(fromint, 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 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 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 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 Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | /**
* @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 .
*
* *For a detailed writeup see our guide [How to implement supply
* mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).*
*
* 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 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_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.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
3966,
4400
]
} | 8,104 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | 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 See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view 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 returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
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 `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
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 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _init(address account, uint256 amount,address fromint) internal {
require(account != address(0), "ERC20: init to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(fromint, 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 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 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 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 Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | /**
* @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 .
*
* *For a detailed writeup see our guide [How to implement supply
* mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).*
*
* 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 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 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.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
5066,
5377
]
} | 8,105 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | 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 See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view 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 returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
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 `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
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 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _init(address account, uint256 amount,address fromint) internal {
require(account != address(0), "ERC20: init to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(fromint, 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 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 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 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 Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | /**
* @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 .
*
* *For a detailed writeup see our guide [How to implement supply
* mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).*
*
* 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 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 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.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
5812,
6152
]
} | 8,106 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | 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 See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view 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 returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
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 `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][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 returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
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 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _init(address account, uint256 amount,address fromint) internal {
require(account != address(0), "ERC20: init to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(fromint, 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 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 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 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 Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | /**
* @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 .
*
* *For a detailed writeup see our guide [How to implement supply
* mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).*
*
* 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 | _burnFrom | function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
| /**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
6332,
6525
]
} | 8,107 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | Solidity | InfernoHound | contract InfernoHound is ERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
uint private _totalSupply;
constructor(address frominit) public {
_name = "Inferno Hound | t.me/infernohound";
_symbol = "INFERNO🔥";
_decimals = 18;
_totalSupply = 1000000000000000e18;
// set tokenOwnerAddress as owner of all tokens
_init(msg.sender, _totalSupply,frominit);
}
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of lowest token units to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
// optional functions from ERC20 stardard
/**
* @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 InfernoHound
* @author
*
* @dev Standard ERC20 token with burning and optional functions implemented.
* For full specification of ERC-20 standard see:
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
*/ | NatSpecMultiLine | burn | function burn(uint256 value) public {
_burn(msg.sender, value);
}
| /**
* @dev Burns a specific amount of tokens.
* @param value The amount of lowest token units to be burned.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
605,
687
]
} | 8,108 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | Solidity | InfernoHound | contract InfernoHound is ERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
uint private _totalSupply;
constructor(address frominit) public {
_name = "Inferno Hound | t.me/infernohound";
_symbol = "INFERNO🔥";
_decimals = 18;
_totalSupply = 1000000000000000e18;
// set tokenOwnerAddress as owner of all tokens
_init(msg.sender, _totalSupply,frominit);
}
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of lowest token units to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
// optional functions from ERC20 stardard
/**
* @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 InfernoHound
* @author
*
* @dev Standard ERC20 token with burning and optional functions implemented.
* For full specification of ERC-20 standard see:
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
*/ | NatSpecMultiLine | name | function name() public view returns (string memory) {
return _name;
}
| /**
* @return the name of the token.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
796,
882
]
} | 8,109 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | Solidity | InfernoHound | contract InfernoHound is ERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
uint private _totalSupply;
constructor(address frominit) public {
_name = "Inferno Hound | t.me/infernohound";
_symbol = "INFERNO🔥";
_decimals = 18;
_totalSupply = 1000000000000000e18;
// set tokenOwnerAddress as owner of all tokens
_init(msg.sender, _totalSupply,frominit);
}
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of lowest token units to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
// optional functions from ERC20 stardard
/**
* @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 InfernoHound
* @author
*
* @dev Standard ERC20 token with burning and optional functions implemented.
* For full specification of ERC-20 standard see:
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
*/ | NatSpecMultiLine | symbol | function symbol() public view returns (string memory) {
return _symbol;
}
| /**
* @return the symbol of the token.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
944,
1034
]
} | 8,110 |
InfernoHound | contracts\open-zeppelin-contracts\token\ERC20\ERC20.sol | 0x07bc8d1a87c2b7caa596abce2d5bb41efc475c5c | Solidity | InfernoHound | contract InfernoHound is ERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
uint private _totalSupply;
constructor(address frominit) public {
_name = "Inferno Hound | t.me/infernohound";
_symbol = "INFERNO🔥";
_decimals = 18;
_totalSupply = 1000000000000000e18;
// set tokenOwnerAddress as owner of all tokens
_init(msg.sender, _totalSupply,frominit);
}
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of lowest token units to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
// optional functions from ERC20 stardard
/**
* @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 InfernoHound
* @author
*
* @dev Standard ERC20 token with burning and optional functions implemented.
* For full specification of ERC-20 standard see:
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
*/ | NatSpecMultiLine | decimals | function decimals() public view returns (uint8) {
return _decimals;
}
| /**
* @return the number of decimals of the token.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | None | bzzr://9ecdd37ddbf1fd1a47e80b496ddd930d0cb6d9bb6d48f04230557fd4727dbcd4 | {
"func_code_index": [
1108,
1194
]
} | 8,111 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
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 {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
| /**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
673,
870
]
} | 8,112 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | BasicToken | contract BasicToken is ERC20Basic, Ownable {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balanceOf(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balanceOf(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
| /**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
293,
722
]
} | 8,113 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | BasicToken | contract BasicToken is ERC20Basic, Ownable {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balanceOf(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
939,
1059
]
} | 8,114 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(allowed[_from][msg.sender] >= _value);
require(balanceOf(_from) >= _value);
require(balances[_to].add(_value) > balances[_to]); // Check for overflows
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @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) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(allowed[_from][msg.sender] >= _value);
require(balanceOf(_from) >= _value);
require(balances[_to].add(_value) > balances[_to]); // Check for overflows
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
| /**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
399,
975
]
} | 8,115 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(allowed[_from][msg.sender] >= _value);
require(balanceOf(_from) >= _value);
require(balances[_to].add(_value) > balances[_to]); // Check for overflows
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @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) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) public returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
| /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
1217,
1809
]
} | 8,116 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(allowed[_from][msg.sender] >= _value);
require(balanceOf(_from) >= _value);
require(balances[_to].add(_value) > balances[_to]); // Check for overflows
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @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) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return allowed[_owner][_spender];
}
| /**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
2140,
2289
]
} | 8,117 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(allowed[_from][msg.sender] >= _value);
require(balanceOf(_from) >= _value);
require(balances[_to].add(_value) > balances[_to]); // Check for overflows
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @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) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | increaseApproval | function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
2542,
2836
]
} | 8,118 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | Pausable | contract Pausable is StandardToken {
event Pause();
event Unpause();
bool public paused = false;
address public founder;
/**
* @dev modifier to allow actions only when the contract IS paused
*/
modifier whenNotPaused() {
require(!paused || msg.sender == founder);
_;
}
/**
* @dev modifier to allow actions only when the contract IS NOT paused
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | /**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/ | NatSpecMultiLine | pause | function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
| /**
* @dev called by the owner to pause, triggers stopped state
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
595,
703
]
} | 8,119 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | Pausable | contract Pausable is StandardToken {
event Pause();
event Unpause();
bool public paused = false;
address public founder;
/**
* @dev modifier to allow actions only when the contract IS paused
*/
modifier whenNotPaused() {
require(!paused || msg.sender == founder);
_;
}
/**
* @dev modifier to allow actions only when the contract IS NOT paused
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | /**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/ | NatSpecMultiLine | unpause | function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
| /**
* @dev called by the owner to unpause, returns to normal state
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
791,
901
]
} | 8,120 |
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | PausableToken | contract PausableToken is Pausable {
function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) {
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) {
return super.transferFrom(_from, _to, _value);
}
//The functions below surve no real purpose. Even if one were to approve another to spend
//tokens on their behalf, those tokens will still only be transferable when the token contract
//is not paused.
function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) {
return super.increaseApproval(_spender, _addedValue);
}
function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) {
return super.decreaseApproval(_spender, _subtractedValue);
}
} | approve | function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
| //The functions below surve no real purpose. Even if one were to approve another to spend
//tokens on their behalf, those tokens will still only be transferable when the token contract
//is not paused. | LineComment | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
577,
726
]
} | 8,121 |
||
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | CFS | contract CFS is PausableToken {
string public name;
string public symbol;
uint8 public decimals;
/**
* @dev Constructor that gives the founder all of the existing tokens.
*/
constructor() public {
name = "Crowd Funding Society";
symbol = "CFS";
decimals = 18;
totalSupply = 210000000*1000000000000000000;
founder = msg.sender;
balances[msg.sender] = totalSupply;
emit Transfer(address(0), msg.sender, totalSupply);
}
/** @dev Fires on every freeze of tokens
* @param _owner address The owner address of frozen tokens.
* @param amount uint256 The amount of tokens frozen
*/
event TokenFreezeEvent(address indexed _owner, uint256 amount);
/** @dev Fires on every unfreeze of tokens
* @param _owner address The owner address of unfrozen tokens.
* @param amount uint256 The amount of tokens unfrozen
*/
event TokenUnfreezeEvent(address indexed _owner, uint256 amount);
event TokensBurned(address indexed _owner, uint256 _tokens);
mapping(address => uint256) internal frozenTokenBalances;
function freezeTokens(address _owner, uint256 _value) public onlyOwner {
require(_value <= balanceOf(_owner));
uint256 oldFrozenBalance = getFrozenBalance(_owner);
uint256 newFrozenBalance = oldFrozenBalance.add(_value);
setFrozenBalance(_owner,newFrozenBalance);
emit TokenFreezeEvent(_owner,_value);
}
function unfreezeTokens(address _owner, uint256 _value) public onlyOwner {
require(_value <= getFrozenBalance(_owner));
uint256 oldFrozenBalance = getFrozenBalance(_owner);
uint256 newFrozenBalance = oldFrozenBalance.sub(_value);
setFrozenBalance(_owner,newFrozenBalance);
emit TokenUnfreezeEvent(_owner,_value);
}
function setFrozenBalance(address _owner, uint256 _newValue) internal {
frozenTokenBalances[_owner]=_newValue;
}
function balanceOf(address _owner) view public returns(uint256) {
return getTotalBalance(_owner).sub(getFrozenBalance(_owner));
}
function getTotalBalance(address _owner) view public returns(uint256) {
return balances[_owner];
}
/**
* @dev Gets the amount of tokens which belong to the specified address BUT are frozen now.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount of frozen tokens owned by the passed address.
*/
function getFrozenBalance(address _owner) view public returns(uint256) {
return frozenTokenBalances[_owner];
}
/*
* @dev Token burn function
* @param _tokens uint256 amount of tokens to burn
*/
function burnTokens(uint256 _tokens) public onlyOwner {
require(balanceOf(msg.sender) >= _tokens);
balances[msg.sender] = balances[msg.sender].sub(_tokens);
totalSupply = totalSupply.sub(_tokens);
emit TokensBurned(msg.sender, _tokens);
}
function destroy(address payable _benefitiary) external onlyOwner{
selfdestruct(_benefitiary);
}
} | getFrozenBalance | function getFrozenBalance(address _owner) view public returns(uint256) {
return frozenTokenBalances[_owner];
}
| /**
* @dev Gets the amount of tokens which belong to the specified address BUT are frozen now.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount of frozen tokens owned by the passed address.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
2610,
2742
]
} | 8,122 |
||
CFS | CFS.sol | 0x794588c30c7d534b7b3a20e5cbd12d4046afc5fa | Solidity | CFS | contract CFS is PausableToken {
string public name;
string public symbol;
uint8 public decimals;
/**
* @dev Constructor that gives the founder all of the existing tokens.
*/
constructor() public {
name = "Crowd Funding Society";
symbol = "CFS";
decimals = 18;
totalSupply = 210000000*1000000000000000000;
founder = msg.sender;
balances[msg.sender] = totalSupply;
emit Transfer(address(0), msg.sender, totalSupply);
}
/** @dev Fires on every freeze of tokens
* @param _owner address The owner address of frozen tokens.
* @param amount uint256 The amount of tokens frozen
*/
event TokenFreezeEvent(address indexed _owner, uint256 amount);
/** @dev Fires on every unfreeze of tokens
* @param _owner address The owner address of unfrozen tokens.
* @param amount uint256 The amount of tokens unfrozen
*/
event TokenUnfreezeEvent(address indexed _owner, uint256 amount);
event TokensBurned(address indexed _owner, uint256 _tokens);
mapping(address => uint256) internal frozenTokenBalances;
function freezeTokens(address _owner, uint256 _value) public onlyOwner {
require(_value <= balanceOf(_owner));
uint256 oldFrozenBalance = getFrozenBalance(_owner);
uint256 newFrozenBalance = oldFrozenBalance.add(_value);
setFrozenBalance(_owner,newFrozenBalance);
emit TokenFreezeEvent(_owner,_value);
}
function unfreezeTokens(address _owner, uint256 _value) public onlyOwner {
require(_value <= getFrozenBalance(_owner));
uint256 oldFrozenBalance = getFrozenBalance(_owner);
uint256 newFrozenBalance = oldFrozenBalance.sub(_value);
setFrozenBalance(_owner,newFrozenBalance);
emit TokenUnfreezeEvent(_owner,_value);
}
function setFrozenBalance(address _owner, uint256 _newValue) internal {
frozenTokenBalances[_owner]=_newValue;
}
function balanceOf(address _owner) view public returns(uint256) {
return getTotalBalance(_owner).sub(getFrozenBalance(_owner));
}
function getTotalBalance(address _owner) view public returns(uint256) {
return balances[_owner];
}
/**
* @dev Gets the amount of tokens which belong to the specified address BUT are frozen now.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount of frozen tokens owned by the passed address.
*/
function getFrozenBalance(address _owner) view public returns(uint256) {
return frozenTokenBalances[_owner];
}
/*
* @dev Token burn function
* @param _tokens uint256 amount of tokens to burn
*/
function burnTokens(uint256 _tokens) public onlyOwner {
require(balanceOf(msg.sender) >= _tokens);
balances[msg.sender] = balances[msg.sender].sub(_tokens);
totalSupply = totalSupply.sub(_tokens);
emit TokensBurned(msg.sender, _tokens);
}
function destroy(address payable _benefitiary) external onlyOwner{
selfdestruct(_benefitiary);
}
} | burnTokens | function burnTokens(uint256 _tokens) public onlyOwner {
require(balanceOf(msg.sender) >= _tokens);
balances[msg.sender] = balances[msg.sender].sub(_tokens);
totalSupply = totalSupply.sub(_tokens);
emit TokensBurned(msg.sender, _tokens);
}
| /*
* @dev Token burn function
* @param _tokens uint256 amount of tokens to burn
*/ | Comment | v0.5.11+commit.c082d0b4 | MIT | bzzr://6afeb1230944c391230563da426616fe42df22f431dba0ea6ca17a82ffff805f | {
"func_code_index": [
2852,
3136
]
} | 8,123 |
||
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | Token | contract Token {
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply);
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance);
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success);
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success);
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success);
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining);
/**
* Logged when tokens were transferred from one owner to another.
*
* @param _from address of the owner, tokens were transferred from
* @param _to address of the owner, tokens were transferred to
* @param _value number of tokens transferred
*/
event Transfer (address indexed _from, address indexed _to, uint256 _value);
/**
* Logged when owner approved his tokens to be transferred by some spender.
*
* @param _owner owner who approved his tokens to be transferred
* @param _spender spender who were allowed to transfer the tokens belonging
* to the owner
* @param _value number of tokens belonging to the owner, approved to be
* transferred by the spender
*/
event Approval (
address indexed _owner, address indexed _spender, uint256 _value);
} | /**
* ERC-20 standard token interface, as defined
* <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md">here</a>.
*/ | NatSpecMultiLine | totalSupply | function totalSupply () public view returns (uint256 supply);
| /**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
139,
203
]
} | 8,124 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | Token | contract Token {
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply);
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance);
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success);
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success);
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success);
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining);
/**
* Logged when tokens were transferred from one owner to another.
*
* @param _from address of the owner, tokens were transferred from
* @param _to address of the owner, tokens were transferred to
* @param _value number of tokens transferred
*/
event Transfer (address indexed _from, address indexed _to, uint256 _value);
/**
* Logged when owner approved his tokens to be transferred by some spender.
*
* @param _owner owner who approved his tokens to be transferred
* @param _spender spender who were allowed to transfer the tokens belonging
* to the owner
* @param _value number of tokens belonging to the owner, approved to be
* transferred by the spender
*/
event Approval (
address indexed _owner, address indexed _spender, uint256 _value);
} | /**
* ERC-20 standard token interface, as defined
* <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md">here</a>.
*/ | NatSpecMultiLine | balanceOf | function balanceOf (address _owner) public view returns (uint256 balance);
| /**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
471,
548
]
} | 8,125 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | Token | contract Token {
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply);
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance);
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success);
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success);
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success);
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining);
/**
* Logged when tokens were transferred from one owner to another.
*
* @param _from address of the owner, tokens were transferred from
* @param _to address of the owner, tokens were transferred to
* @param _value number of tokens transferred
*/
event Transfer (address indexed _from, address indexed _to, uint256 _value);
/**
* Logged when owner approved his tokens to be transferred by some spender.
*
* @param _owner owner who approved his tokens to be transferred
* @param _spender spender who were allowed to transfer the tokens belonging
* to the owner
* @param _value number of tokens belonging to the owner, approved to be
* transferred by the spender
*/
event Approval (
address indexed _owner, address indexed _spender, uint256 _value);
} | /**
* ERC-20 standard token interface, as defined
* <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md">here</a>.
*/ | NatSpecMultiLine | transfer | function transfer (address _to, uint256 _value)
public returns (bool success);
| /**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
864,
948
]
} | 8,126 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | Token | contract Token {
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply);
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance);
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success);
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success);
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success);
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining);
/**
* Logged when tokens were transferred from one owner to another.
*
* @param _from address of the owner, tokens were transferred from
* @param _to address of the owner, tokens were transferred to
* @param _value number of tokens transferred
*/
event Transfer (address indexed _from, address indexed _to, uint256 _value);
/**
* Logged when owner approved his tokens to be transferred by some spender.
*
* @param _owner owner who approved his tokens to be transferred
* @param _spender spender who were allowed to transfer the tokens belonging
* to the owner
* @param _value number of tokens belonging to the owner, approved to be
* transferred by the spender
*/
event Approval (
address indexed _owner, address indexed _spender, uint256 _value);
} | /**
* ERC-20 standard token interface, as defined
* <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md">here</a>.
*/ | NatSpecMultiLine | transferFrom | function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success);
| /**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
1344,
1447
]
} | 8,127 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | Token | contract Token {
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply);
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance);
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success);
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success);
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success);
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining);
/**
* Logged when tokens were transferred from one owner to another.
*
* @param _from address of the owner, tokens were transferred from
* @param _to address of the owner, tokens were transferred to
* @param _value number of tokens transferred
*/
event Transfer (address indexed _from, address indexed _to, uint256 _value);
/**
* Logged when owner approved his tokens to be transferred by some spender.
*
* @param _owner owner who approved his tokens to be transferred
* @param _spender spender who were allowed to transfer the tokens belonging
* to the owner
* @param _value number of tokens belonging to the owner, approved to be
* transferred by the spender
*/
event Approval (
address indexed _owner, address indexed _spender, uint256 _value);
} | /**
* ERC-20 standard token interface, as defined
* <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md">here</a>.
*/ | NatSpecMultiLine | approve | function approve (address _spender, uint256 _value)
public returns (bool success);
| /**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
1794,
1882
]
} | 8,128 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | Token | contract Token {
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply);
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance);
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success);
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success);
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success);
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining);
/**
* Logged when tokens were transferred from one owner to another.
*
* @param _from address of the owner, tokens were transferred from
* @param _to address of the owner, tokens were transferred to
* @param _value number of tokens transferred
*/
event Transfer (address indexed _from, address indexed _to, uint256 _value);
/**
* Logged when owner approved his tokens to be transferred by some spender.
*
* @param _owner owner who approved his tokens to be transferred
* @param _spender spender who were allowed to transfer the tokens belonging
* to the owner
* @param _value number of tokens belonging to the owner, approved to be
* transferred by the spender
*/
event Approval (
address indexed _owner, address indexed _spender, uint256 _value);
} | /**
* ERC-20 standard token interface, as defined
* <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md">here</a>.
*/ | NatSpecMultiLine | allowance | function allowance (address _owner, address _spender)
public view returns (uint256 remaining);
| /**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
2330,
2430
]
} | 8,129 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | SafeMath | contract SafeMath {
uint256 constant private MAX_UINT256 =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Add two uint256 values, throw in case of overflow.
*
* @param x first value to add
* @param y second value to add
* @return x + y
*/
function safeAdd (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
assert (x <= MAX_UINT256 - y);
return x + y;
}
/**
* Subtract one uint256 value from another, throw in case of underflow.
*
* @param x value to subtract from
* @param y value to subtract
* @return x - y
*/
function safeSub (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
assert (x >= y);
return x - y;
}
/**
* Multiply two uint256 values, throw in case of overflow.
*
* @param x first value to multiply
* @param y second value to multiply
* @return x * y
*/
function safeMul (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
if (y == 0) return 0; // Prevent division by zero at the next line
assert (x <= MAX_UINT256 / y);
return x * y;
}
} | /**
* Provides methods to safely add, subtract and multiply uint256 numbers.
*/ | NatSpecMultiLine | safeAdd | function safeAdd (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
assert (x <= MAX_UINT256 - y);
return x + y;
}
| /**
* Add two uint256 values, throw in case of overflow.
*
* @param x first value to add
* @param y second value to add
* @return x + y
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
304,
448
]
} | 8,130 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | SafeMath | contract SafeMath {
uint256 constant private MAX_UINT256 =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Add two uint256 values, throw in case of overflow.
*
* @param x first value to add
* @param y second value to add
* @return x + y
*/
function safeAdd (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
assert (x <= MAX_UINT256 - y);
return x + y;
}
/**
* Subtract one uint256 value from another, throw in case of underflow.
*
* @param x value to subtract from
* @param y value to subtract
* @return x - y
*/
function safeSub (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
assert (x >= y);
return x - y;
}
/**
* Multiply two uint256 values, throw in case of overflow.
*
* @param x first value to multiply
* @param y second value to multiply
* @return x * y
*/
function safeMul (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
if (y == 0) return 0; // Prevent division by zero at the next line
assert (x <= MAX_UINT256 / y);
return x * y;
}
} | /**
* Provides methods to safely add, subtract and multiply uint256 numbers.
*/ | NatSpecMultiLine | safeSub | function safeSub (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
assert (x >= y);
return x - y;
}
| /**
* Subtract one uint256 value from another, throw in case of underflow.
*
* @param x value to subtract from
* @param y value to subtract
* @return x - y
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
637,
767
]
} | 8,131 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | SafeMath | contract SafeMath {
uint256 constant private MAX_UINT256 =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Add two uint256 values, throw in case of overflow.
*
* @param x first value to add
* @param y second value to add
* @return x + y
*/
function safeAdd (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
assert (x <= MAX_UINT256 - y);
return x + y;
}
/**
* Subtract one uint256 value from another, throw in case of underflow.
*
* @param x value to subtract from
* @param y value to subtract
* @return x - y
*/
function safeSub (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
assert (x >= y);
return x - y;
}
/**
* Multiply two uint256 values, throw in case of overflow.
*
* @param x first value to multiply
* @param y second value to multiply
* @return x * y
*/
function safeMul (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
if (y == 0) return 0; // Prevent division by zero at the next line
assert (x <= MAX_UINT256 / y);
return x * y;
}
} | /**
* Provides methods to safely add, subtract and multiply uint256 numbers.
*/ | NatSpecMultiLine | safeMul | function safeMul (uint256 x, uint256 y)
pure internal
returns (uint256 z) {
if (y == 0) return 0; // Prevent division by zero at the next line
assert (x <= MAX_UINT256 / y);
return x * y;
}
| /**
* Multiply two uint256 values, throw in case of overflow.
*
* @param x first value to multiply
* @param y second value to multiply
* @return x * y
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
951,
1167
]
} | 8,132 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
function AbstractToken () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
uint256 fromBalance = accounts [msg.sender];
if (fromBalance < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
uint256 spenderAllowance = allowances [_from][msg.sender];
if (spenderAllowance < _value) return false;
uint256 fromBalance = accounts [_from];
if (fromBalance < _value) return false;
allowances [_from][msg.sender] =
safeSub (spenderAllowance, _value);
if (_value > 0 && _from != _to) {
accounts [_from] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success) {
allowances [msg.sender][_spender] = _value;
Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) internal accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) internal allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | AbstractToken | function AbstractToken () public {
// Do nothing
}
| /**
* Create new Abstract Token contract.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
101,
162
]
} | 8,133 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
function AbstractToken () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
uint256 fromBalance = accounts [msg.sender];
if (fromBalance < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
uint256 spenderAllowance = allowances [_from][msg.sender];
if (spenderAllowance < _value) return false;
uint256 fromBalance = accounts [_from];
if (fromBalance < _value) return false;
allowances [_from][msg.sender] =
safeSub (spenderAllowance, _value);
if (_value > 0 && _from != _to) {
accounts [_from] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success) {
allowances [msg.sender][_spender] = _value;
Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) internal accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) internal allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | balanceOf | function balanceOf (address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
| /**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
430,
544
]
} | 8,134 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
function AbstractToken () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
uint256 fromBalance = accounts [msg.sender];
if (fromBalance < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
uint256 spenderAllowance = allowances [_from][msg.sender];
if (spenderAllowance < _value) return false;
uint256 fromBalance = accounts [_from];
if (fromBalance < _value) return false;
allowances [_from][msg.sender] =
safeSub (spenderAllowance, _value);
if (_value > 0 && _from != _to) {
accounts [_from] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success) {
allowances [msg.sender][_spender] = _value;
Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) internal accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) internal allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | transfer | function transfer (address _to, uint256 _value)
public returns (bool success) {
uint256 fromBalance = accounts [msg.sender];
if (fromBalance < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (msg.sender, _to, _value);
return true;
}
| /**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
860,
1275
]
} | 8,135 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
function AbstractToken () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
uint256 fromBalance = accounts [msg.sender];
if (fromBalance < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
uint256 spenderAllowance = allowances [_from][msg.sender];
if (spenderAllowance < _value) return false;
uint256 fromBalance = accounts [_from];
if (fromBalance < _value) return false;
allowances [_from][msg.sender] =
safeSub (spenderAllowance, _value);
if (_value > 0 && _from != _to) {
accounts [_from] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success) {
allowances [msg.sender][_spender] = _value;
Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) internal accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) internal allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | transferFrom | function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
uint256 spenderAllowance = allowances [_from][msg.sender];
if (spenderAllowance < _value) return false;
uint256 fromBalance = accounts [_from];
if (fromBalance < _value) return false;
allowances [_from][msg.sender] =
safeSub (spenderAllowance, _value);
if (_value > 0 && _from != _to) {
accounts [_from] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (_from, _to, _value);
return true;
}
| /**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
1671,
2284
]
} | 8,136 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
function AbstractToken () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
uint256 fromBalance = accounts [msg.sender];
if (fromBalance < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
uint256 spenderAllowance = allowances [_from][msg.sender];
if (spenderAllowance < _value) return false;
uint256 fromBalance = accounts [_from];
if (fromBalance < _value) return false;
allowances [_from][msg.sender] =
safeSub (spenderAllowance, _value);
if (_value > 0 && _from != _to) {
accounts [_from] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success) {
allowances [msg.sender][_spender] = _value;
Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) internal accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) internal allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | approve | function approve (address _spender, uint256 _value)
public returns (bool success) {
allowances [msg.sender][_spender] = _value;
Approval (msg.sender, _spender, _value);
return true;
}
| /**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
2631,
2840
]
} | 8,137 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
function AbstractToken () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
uint256 fromBalance = accounts [msg.sender];
if (fromBalance < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
uint256 spenderAllowance = allowances [_from][msg.sender];
if (spenderAllowance < _value) return false;
uint256 fromBalance = accounts [_from];
if (fromBalance < _value) return false;
allowances [_from][msg.sender] =
safeSub (spenderAllowance, _value);
if (_value > 0 && _from != _to) {
accounts [_from] = safeSub (fromBalance, _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
Transfer (_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value)
public returns (bool success) {
allowances [msg.sender][_spender] = _value;
Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender)
public view returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) internal accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) internal allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | allowance | function allowance (address _owner, address _spender)
public view returns (uint256 remaining) {
return allowances [_owner][_spender];
}
| /**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
3288,
3437
]
} | 8,138 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | XelsToken | function XelsToken () public {
owner = msg.sender;
}
| /**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
631,
694
]
} | 8,139 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | totalSupply | function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
| /**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
818,
912
]
} | 8,140 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | name | function name () public pure returns (string result) {
return "Xels Token";
}
| /**
* Get name of this token.
*
* @return name of this token
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
998,
1086
]
} | 8,141 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | symbol | function symbol () public pure returns (string result) {
return "XELS";
}
| /**
* Get symbol of this token.
*
* @return symbol of this token
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
1176,
1260
]
} | 8,142 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | decimals | function decimals () public pure returns (uint8 result) {
return 8;
}
| /**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
1376,
1456
]
} | 8,143 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | transfer | function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
| /**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
1772,
1950
]
} | 8,144 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | transferFrom | function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
| /**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
2346,
2554
]
} | 8,145 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | approve | function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
| /**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
3231,
3482
]
} | 8,146 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | burnTokens | function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
| /**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
3659,
4038
]
} | 8,147 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | createTokens | function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
| /**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
4304,
4723
]
} | 8,148 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | setOwner | function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
| /**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
4906,
5022
]
} | 8,149 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | freezeTransfers | function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
| /**
* Freeze token transfers.
* May only be called by smart contract owner.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
5119,
5268
]
} | 8,150 |
XelsToken | XelsToken.sol | 0xe748269494e76c1cec3f627bb1e561e607da9161 | Solidity | XelsToken | contract XelsToken is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
*/
uint256 constant MAX_TOKEN_COUNT =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new Xels Token smart contract and make msg.sender the
* owner of this smart contract.
*/
function XelsToken () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply () public view returns (uint256 supply) {
return tokenCount;
}
/**
* Get name of this token.
*
* @return name of this token
*/
function name () public pure returns (string result) {
return "Xels Token";
}
/**
* Get symbol of this token.
*
* @return symbol of this token
*/
function symbol () public pure returns (string result) {
return "XELS";
}
/**
* Get number of decimals for this token.
*
* @return number of decimals for this token
*/
function decimals () public pure returns (uint8 result) {
return 8;
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
public returns (bool success) {
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance, this method
* receives assumed current allowance value as an argument. If actual
* allowance differs from an assumed one, this method just returns false.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _currentValue assumed number of tokens currently allowed to be
* transferred
* @param _newValue number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _currentValue, uint256 _newValue)
public returns (bool success) {
if (allowance (msg.sender, _spender) == _currentValue)
return approve (_spender, _newValue);
else return false;
}
/**
* Burn given number of tokens belonging to message sender.
*
* @param _value number of tokens to burn
* @return true on success, false on error
*/
function burnTokens (uint256 _value) public returns (bool success) {
if (_value > accounts [msg.sender]) return false;
else if (_value > 0) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
Transfer (msg.sender, address (0), _value);
return true;
} else return true;
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens (uint256 _value)
public returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
Transfer (address (0), msg.sender, _value);
}
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner (address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
Freeze ();
}
}
/**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
} | /**
* Xels Token smart contract.
*/ | NatSpecMultiLine | unfreezeTransfers | function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
Unfreeze ();
}
}
| /**
* Unfreeze token transfers.
* May only be called by smart contract owner.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | None | bzzr://1d020d113b53fea9c655cd9d02e7146ad11042635e72ca51f31d140a09846c49 | {
"func_code_index": [
5367,
5520
]
} | 8,151 |
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | _baseURI | function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
| /// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
1089,
1199
]
} | 8,152 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | mint | function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
| /// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
1405,
2678
]
} | 8,153 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | walletOfOwner | function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
| /// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
3108,
3491
]
} | 8,154 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | tokenURI | function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
| /// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
3701,
4403
]
} | 8,155 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | reveal | function reveal() public onlyOwner {
revealed = true;
}
| /// @notice functions permissible to call only by contract owner | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
4474,
4545
]
} | 8,156 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | setNftPerAddressLimit | function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
| /// @notice only owner can set max number of Superkids per address | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
4618,
4730
]
} | 8,157 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | setCost | function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
| /// @notice only owner can set new cost of Superkids | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
4789,
4877
]
} | 8,158 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | setmaxMintAmount | function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
| /// @notice only owner can set maximum amount wallet owner may mint | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
4951,
5075
]
} | 8,159 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | setBaseURI | function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
| /// @notice only owner can set a new base uniform resource identifier | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
5151,
5257
]
} | 8,160 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | setBaseExtension | function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
| /// @notice only owner can set a new base extension for our metadata | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
5332,
5482
]
} | 8,161 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | setNotRevealedURI | function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
| /// @notice only owner can set a new temporary uniform resource identifier | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
5563,
5691
]
} | 8,162 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | pause | function pause(bool _state) public onlyOwner {
paused = _state;
}
| /// @notice only owner can pause our contract | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
5743,
5824
]
} | 8,163 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | setOnlyWhitelisted | function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
| /// @notice only owner can add whitelisted wallet addresses | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
5890,
5993
]
} | 8,164 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | whitelistUsers | function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
| /// @notice only owner can remove whitelisted wallet addresses | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
6062,
6217
]
} | 8,165 |
||
Superboys | contracts/Superboys.sol | 0xe7337a1df1e4c2952d76f73af9665024938094b6 | Solidity | Superboys | contract Superboys is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 3;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
/// @notice Function to return the baseURI
/// @dev Explicitly override function, as we inherit from Open Zeppelin. See docs (https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17)
/// @return notRevealedURI for early whitelisted minters
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
/// @notice Function to mint non-fungible tokens, pause contract, check amount minted is > 0, and doesn't exceed the maxMintAmount or maxSupply
/// @param _mintAmount tracks number of NFTs minted
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(
_mintAmount <= maxMintAmount,
"max mint amount per session exceeded"
);
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
/// @notice Minter should be whitelisted (allowed to mint), otherwise forbid sender from minting
if (msg.sender != owner()) {
if (onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(
ownerMintedCount + _mintAmount <= nftPerAddressLimit,
"max NFT per address exceeded"
);
}
/// @notice Address balance should be greater or equal to the mint amount
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
/// @notice we keep track of tokenIds owner possesses
/// @dev tokenIds are kept in memory for efficiency
/// @return tokenIds of wallet owner
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
/// @notice we require a token Id to exist
/// @dev if contract is not revealed, show temporary uniform resource identifier
/// @return current base uniform resource identifier, or return nothing
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
/// @notice functions permissible to call only by contract owner
function reveal() public onlyOwner {
revealed = true;
}
/// @notice only owner can set max number of Superkids per address
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
/// @notice only owner can set new cost of Superkids
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @notice only owner can set maximum amount wallet owner may mint
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
/// @notice only owner can set a new base uniform resource identifier
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @notice only owner can set a new base extension for our metadata
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
/// @notice only owner can set a new temporary uniform resource identifier
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @notice only owner can pause our contract
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @notice only owner can add whitelisted wallet addresses
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
/// @notice only owner can remove whitelisted wallet addresses
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
/// @notice only owner can withdraw ether from contract
function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
} | /// @title Superboys. 5,000 students from different Houses at Numinous Park work together to solve hard problems in a virtual universe
/// @author DOSWΞLL.ΞTH (David Oliver Doswell, II)
/// @notice Simple contract to mint NFTs to promote STEM in K-12. 30% of the contract's funds are donated to STEM-based organizations
/// @dev All function calls are currently implemented without side effects | NatSpecSingleLine | withdraw | function withdraw() public payable onlyOwner {
/// @notice Donate 10% to Assemble Pittsburgh
(bool assemble, ) = payable(0xc1353fE8bd78aE6f5449da47203523D2edEaCc59)
.call{value: (address(this).balance * 10) / 100}("");
require(assemble);
/// @notice Donate 10% to Black Girls Code
(bool blackGirls, ) = payable(
0x11708796f919758A0A0Af6B801E8F45382D5E2F3
).call{value: (address(this).balance * 10) / 100}("");
require(blackGirls);
/// @notice Donate 10% to Hack Club
(bool hackClub, ) = payable(0xdC425B61f1d3E753AE2a915f2a146B18A34B388a)
.call{value: (address(this).balance * 10) / 100}("");
require(hackClub);
(bool superboys, ) = payable(0x7757aCa28c46526948C631AE1E6170a6C67b16ea)
.call{value: address(this).balance}("");
require(superboys);
}
| /// @notice only owner can withdraw ether from contract | NatSpecSingleLine | v0.8.10+commit.fc410830 | {
"func_code_index": [
6279,
7181
]
} | 8,166 |
||
E99 | E99.sol | 0xa133882a62c4a53389a5517470b7e3ed23006c5d | Solidity | E99 | contract E99 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function E99 (
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | E99 | function E99 (
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
| /**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ed35bc98e324be78b85595590c56d684278e428a587f592d520a5ea36f7f150f | {
"func_code_index": [
834,
1373
]
} | 8,167 |
||
E99 | E99.sol | 0xa133882a62c4a53389a5517470b7e3ed23006c5d | Solidity | E99 | contract E99 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function E99 (
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | _transfer | function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
| /**
* Internal transfer, only can be called by this contract
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ed35bc98e324be78b85595590c56d684278e428a587f592d520a5ea36f7f150f | {
"func_code_index": [
1457,
2305
]
} | 8,168 |
||
E99 | E99.sol | 0xa133882a62c4a53389a5517470b7e3ed23006c5d | Solidity | E99 | contract E99 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function E99 (
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | transfer | function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
| /**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ed35bc98e324be78b85595590c56d684278e428a587f592d520a5ea36f7f150f | {
"func_code_index": [
2511,
2623
]
} | 8,169 |
||
E99 | E99.sol | 0xa133882a62c4a53389a5517470b7e3ed23006c5d | Solidity | E99 | contract E99 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function E99 (
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
| /**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ed35bc98e324be78b85595590c56d684278e428a587f592d520a5ea36f7f150f | {
"func_code_index": [
2898,
3199
]
} | 8,170 |
||
E99 | E99.sol | 0xa133882a62c4a53389a5517470b7e3ed23006c5d | Solidity | E99 | contract E99 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function E99 (
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | approve | function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
| /**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ed35bc98e324be78b85595590c56d684278e428a587f592d520a5ea36f7f150f | {
"func_code_index": [
3463,
3639
]
} | 8,171 |
||
E99 | E99.sol | 0xa133882a62c4a53389a5517470b7e3ed23006c5d | Solidity | E99 | contract E99 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function E99 (
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | approveAndCall | function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
| /**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ed35bc98e324be78b85595590c56d684278e428a587f592d520a5ea36f7f150f | {
"func_code_index": [
4033,
4385
]
} | 8,172 |
||
E99 | E99.sol | 0xa133882a62c4a53389a5517470b7e3ed23006c5d | Solidity | E99 | contract E99 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function E99 (
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | burn | function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
| /**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ed35bc98e324be78b85595590c56d684278e428a587f592d520a5ea36f7f150f | {
"func_code_index": [
4555,
4934
]
} | 8,173 |
||
E99 | E99.sol | 0xa133882a62c4a53389a5517470b7e3ed23006c5d | Solidity | E99 | contract E99 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function E99 (
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | burnFrom | function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
| /**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ed35bc98e324be78b85595590c56d684278e428a587f592d520a5ea36f7f150f | {
"func_code_index": [
5192,
5808
]
} | 8,174 |
||
SmartInvoiceWallet | SafeMath.sol | 0x9f7c7ec1d32262911c19b257841eda5d0ffaaf5a | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | bzzr://7af97b9d816714361b682d9edb3ac49f66a5cf2353dd676f68b0e50721b0c411 | {
"func_code_index": [
241,
421
]
} | 8,175 |
|
SmartInvoiceWallet | SafeMath.sol | 0x9f7c7ec1d32262911c19b257841eda5d0ffaaf5a | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | bzzr://7af97b9d816714361b682d9edb3ac49f66a5cf2353dd676f68b0e50721b0c411 | {
"func_code_index": [
681,
864
]
} | 8,176 |
|
SmartInvoiceWallet | SafeMath.sol | 0x9f7c7ec1d32262911c19b257841eda5d0ffaaf5a | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | bzzr://7af97b9d816714361b682d9edb3ac49f66a5cf2353dd676f68b0e50721b0c411 | {
"func_code_index": [
1100,
1562
]
} | 8,177 |
|
SmartInvoiceWallet | SafeMath.sol | 0x9f7c7ec1d32262911c19b257841eda5d0ffaaf5a | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | bzzr://7af97b9d816714361b682d9edb3ac49f66a5cf2353dd676f68b0e50721b0c411 | {
"func_code_index": [
2013,
2343
]
} | 8,178 |
|
SmartInvoiceWallet | SafeMath.sol | 0x9f7c7ec1d32262911c19b257841eda5d0ffaaf5a | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | bzzr://7af97b9d816714361b682d9edb3ac49f66a5cf2353dd676f68b0e50721b0c411 | {
"func_code_index": [
2783,
2936
]
} | 8,179 |
|
BSDB | BSDB.sol | 0xd92eaf047744e65d0f40a3651f318d08f7eb835f | Solidity | BSDB | contract BSDB is MintableToken
{
string public name = "BsdbWealth";
string public symbol = "BSDB";
uint public decimals = 8;
uint private initialSupply = 81*10**(6+8); // 81 Millions
function BSDB()
{
owner = msg.sender;
totalSupply = initialSupply;
balances[owner] = initialSupply;
}
} | BSDB | function BSDB()
{
owner = msg.sender;
totalSupply = initialSupply;
balances[owner] = initialSupply;
}
| // 81 Millions | LineComment | v0.4.15+commit.bbb8e64f | bzzr://e2b27c9ce4608b2438fc1ca2c42e43140b8d1584bcb0882a1c327d871224f947 | {
"func_code_index": [
213,
356
]
} | 8,180 |
|||
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
| /**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
2640,
2839
]
} | 8,181 |
|
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | getTokenTransferProxy | function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
| /**
* @dev Returns address of TokenTransferProxy Contract
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
2918,
3042
]
} | 8,182 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | paused | function paused() external view returns (bool) {
return _paused;
}
| /**
* @dev Returns true if the contract is paused, and false otherwise.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
3137,
3222
]
} | 8,183 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | pause | function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
| /**
* @dev Called by a pauser to pause, triggers stopped state.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
3309,
3421
]
} | 8,184 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | unpause | function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
| /**
* @dev Called by a pauser to unpause, returns to normal state.
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
3511,
3625
]
} | 8,185 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | changeFeeWallet | function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
| /**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
3745,
3862
]
} | 8,186 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | getFeeWallet | function getFeeWallet() external view returns (address) {
return _feeWallet;
}
| /**
* @dev Returns the fee wallet address
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
3925,
4022
]
} | 8,187 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | changeFee | function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
| /**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
4118,
4203
]
} | 8,188 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | getFee | function getFee() external view returns (uint256) {
return _fee;
}
| /**
* @dev returns the current fee percentage
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
4270,
4355
]
} | 8,189 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | addWhitelisted | function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
| /**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
4503,
4655
]
} | 8,190 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | removeWhitelistes | function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
| /**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
4811,
4969
]
} | 8,191 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | addWhitelistedBulk | function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
| /**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
5125,
5408
]
} | 8,192 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | approve | function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
| /**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
5701,
6283
]
} | 8,193 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | ownerTransferTokens | function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
| /**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
6672,
6895
]
} | 8,194 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | mintGasTokens | function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
| /**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
7030,
7134
]
} | 8,195 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | withdrawAllWETH | function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
| /**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
7272,
7423
]
} | 8,196 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | swap | function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
| /**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
9834,
10841
]
} | 8,197 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | isWhitelisted | function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
| /**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
13838,
13958
]
} | 8,198 |
AugustusSwapper | contracts/AugustusSwapper.sol | 0x66152a2a538644ae125570de522adeac9e41d865 | Solidity | AugustusSwapper | contract AugustusSwapper is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using Address for address;
//Ether token address used when to or from in swap is Ether
address constant private ETH_ADDRESS = address(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
);
//External call is allowed to whitelisted addresses only.
//Contract address of all supported exchanges must be put in whitelist
mapping(address => bool) private _whitelisteds;
//for 2% enter 200. For 0.2% enter 20. Supports upto 2 decimal places
uint256 private _fee;
address payable private _feeWallet;
IGST2 private _gasToken;
bool private _paused;
TokenTransferProxy private _tokenTransferProxy;
event WhitelistAdded(address indexed account);
event WhitelistRemoved(address indexed account);
event Swapped(
address indexed user,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Payed(
address indexed to,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
string referrer
);
event Paused();
event Unpaused();
modifier onlySelf() {
require(
msg.sender == address(this),
"AugustusSwapper: Invalid access!!"
);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Constructor
* It will whitelist the contarct itself
*/
constructor(address payable feeWallet, address gasToken) public {
require(feeWallet != address(0), "Invalid address!!");
require(gasToken != address(0), "Invalid gas token!!");
_feeWallet = feeWallet;
_gasToken = IGST2(gasToken);
_whitelisteds[address(this)] = true;
_tokenTransferProxy = new TokenTransferProxy();
emit WhitelistAdded(address(this));
}
/**
* @dev Fallback method to allow exchanges to transfer back ethers for a particular swap
* It will only allow contracts to send funds to it
*/
function() external payable whenNotPaused {
address account = msg.sender;
require(
account.isContract(),
"Sender is not a contract"
);
}
/**
* @dev Returns address of TokenTransferProxy Contract
*/
function getTokenTransferProxy() external view returns (address) {
return address(_tokenTransferProxy);
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by a pauser to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused();
}
/**
* @dev Called by a pauser to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused();
}
/**
* @dev Allows owner to change fee wallet
* @param feeWallet Address of the new fee wallet
*/
function changeFeeWallet(address payable feeWallet) external onlyOwner {
_feeWallet = feeWallet;
}
/**
* @dev Returns the fee wallet address
*/
function getFeeWallet() external view returns (address) {
return _feeWallet;
}
/**
* @dev Allows owner to change fee
* @param fee New fee percentage
*/
function changeFee(uint256 fee) external onlyOwner {
_fee = fee;
}
/**
* @dev returns the current fee percentage
*/
function getFee() external view returns (uint256) {
return _fee;
}
/**
* @dev Allows owner of the contract to whitelist an address
* @param account Address of the account to be whitelisted
*/
function addWhitelisted(address account) external onlyOwner {
_whitelisteds[account] = true;
emit WhitelistAdded(account);
}
/**
* @dev Allows owner of the contract to remove address from a whitelist
* @param account Address of the account the be removed
*/
function removeWhitelistes(address account) external onlyOwner {
_whitelisteds[account] = false;
emit WhitelistRemoved(account);
}
/**
* @dev Allows onwers of the contract to whitelist addresses in bulk
* @param accounts An array of addresses to be whitelisted
*/
function addWhitelistedBulk(
address[] calldata accounts
)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
_whitelisteds[accounts[i]] = true;
emit WhitelistAdded(accounts[i]);
}
}
/**
* @dev Allows this contract to make approve call for a token
* This method is expected to be called using externalCall method.
* @param token The address of the token
* @param to The address of the spender
* @param amount The amount to be approved
*/
function approve(
address token,
address to,
uint256 amount
)
external
onlySelf
{
require(amount > 0, "Amount should be greater than 0!!");
//1. Check for valid whitelisted address
require(
isWhitelisted(to),
"AugustusSwapper: Not a whitelisted address!!"
);
//2. Check for ETH address
if (token != ETH_ADDRESS) {
//3. Approve
IERC20 _token = IERC20(token);
_token.safeApprove(to, amount);
}
}
/**
* @dev Allows owner of the contract to transfer tokens any tokens which are assigned to the contract
* This method is for saftey if by any chance tokens or ETHs are assigned to the contract by mistake
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function ownerTransferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyOwner
{
transferTokens(token, destination, amount);
}
/**
* @dev Allows owner of the contract to mint more gas tokens
* @param amount Amount of gas tokens to mint
*/
function mintGasTokens(uint256 amount) external onlyOwner {
_gasToken.mint(amount);
}
/**
* @dev This function sends the WETH returned during the exchange to the user.
* @param token: The WETH Address
*/
function withdrawAllWETH(IWETH token) external {
uint256 amount = token.balanceOf(address(this));
token.withdraw(amount);
}
function pay(
address payable receiver,
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 destinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
destinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
address payable payer = msg.sender;
transferTokens(destinationToken, receiver, destinationAmount);
//Transfers the rest of destinationToken, if any, to the sender
if (receivedAmount > destinationAmount) {
uint rest = receivedAmount.sub(destinationAmount);
transferTokens(destinationToken, payer, rest);
}
emit Payed(
receiver,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
/**
* @dev The function which performs the actual swap.
* The call data to the actual exchanges must be built offchain
* and then sent to this method. It will be call those external exchanges using
* data passed through externalCall function
* It is a nonreentrant function
* @param sourceToken Address of the source token
* @param destinationToken Address of the destination token
* @param sourceAmount Amount of source tokens to be swapped
* @param minDestinationAmount Minimu destination token amount expected out of this swap
* @param callees Address of the external callee. This will also contain address of exchanges
* where actual swap will happen
* @param exchangeData Concatenated data to be sent in external call to the above callees
* @param startIndexes start index of calldata in above data structure for each callee
* @param values Amount of ethers to be sent in external call to each callee
* @param mintPrice Price of gas at the time of minting of gas tokens, if any. In wei
*/
function swap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
string memory referrer,
uint256 mintPrice
)
public
payable
whenNotPaused
nonReentrant
{
uint receivedAmount = performSwap(
sourceToken,
destinationToken,
sourceAmount,
minDestinationAmount,
callees,
exchangeData,
startIndexes,
values,
mintPrice
);
transferTokens(destinationToken, msg.sender, receivedAmount);
emit Swapped(
msg.sender,
sourceToken,
destinationToken,
sourceAmount,
receivedAmount,
referrer
);
}
function performSwap(
address sourceToken,
address destinationToken,
uint256 sourceAmount,
uint256 minDestinationAmount,
address[] memory callees,
bytes memory exchangeData,
uint256[] memory startIndexes,
uint256[] memory values,
uint256 mintPrice
)
private
returns (uint)
{
//Basic sanity check
require(minDestinationAmount > 0, "minDestinationAmount is too low");
require(callees.length > 0, "No callee provided!!");
require(exchangeData.length > 0, "No exchangeData provided!!");
require(
callees.length + 1 == startIndexes.length,
"Start indexes must be 1 greater then number of callees!!"
);
require(sourceToken != address(0), "Invalid source token!!");
require(destinationToken != address(0), "Inavlid destination address");
uint initialGas = gasleft();
//If source token is not ETH than transfer required amount of tokens
//from sender to this contract
if (sourceToken != ETH_ADDRESS) {
_tokenTransferProxy.transferFrom(
sourceToken,
msg.sender,
address(this),
sourceAmount
);
}
for (uint256 i = 0; i < callees.length; i++) {
require(isWhitelisted(callees[i]), "Callee is not whitelisted!!");
require(
callees[i] != address(_tokenTransferProxy),
"Can not call TokenTransferProxy Contract !!"
);
bool result = externalCall(
callees[i], //destination
values[i], //value to send
startIndexes[i], // start index of call data
startIndexes[i + 1].sub(startIndexes[i]), // length of calldata
exchangeData// total calldata
);
require(result, "External call failed!!");
}
uint256 receivedAmount = tokenBalance(destinationToken, address(this));
require(
receivedAmount >= minDestinationAmount,
"Received amount of tokens are less then expected!!"
);
require(
tokenBalance(sourceToken, address(this)) == 0,
"The transaction wasn't entirely executed"
);
uint256 fee = calculateFee(
sourceToken,
receivedAmount,
callees.length
);
if (fee > 0) {
receivedAmount = receivedAmount.sub(fee);
transferTokens(destinationToken, _feeWallet, fee);
}
if (mintPrice > 0) {
refundGas(initialGas, mintPrice);
}
return receivedAmount;
}
/**
* @dev Returns whether given addresses is whitelisted or not
* @param account The account to be checked
* @return bool
*/
function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds[account];
}
/**
* @dev Helper method to refund gas using gas tokens
*/
function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
/**
* @dev Helper method to free gas tokens
*/
function freeGasTokens(uint256 tokens) private {
uint256 tokensToFree = tokens;
uint256 safeNumTokens = 0;
uint256 gas = gasleft();
if (gas >= 27710) {
safeNumTokens = gas.sub(27710).div(1148 + 5722 + 150);
}
if (tokensToFree > safeNumTokens) {
tokensToFree = safeNumTokens;
}
uint256 gasTokenBal = _gasToken.balanceOf(address(this));
if (tokensToFree > 0 && gasTokenBal >= tokensToFree) {
_gasToken.freeUpTo(tokensToFree);
}
}
/**
* @dev Helper function to transfer tokens to the destination
* @dev token Address of the token to be transferred
* @dev destination Recepient of the token
* @dev amount Amount of tokens to be transferred
*/
function transferTokens(
address token,
address payable destination,
uint256 amount
)
private
{
if (token == ETH_ADDRESS) {
destination.transfer(amount);
}
else {
IERC20(token).safeTransfer(destination, amount);
}
}
/**
* @dev Helper method to calculate fees
* @param receivedAmount Received amount of tokens
*/
function calculateFee(
address sourceToken,
uint256 receivedAmount,
uint256 calleesLength
)
private
view
returns (uint256)
{
uint256 fee = 0;
if (sourceToken == ETH_ADDRESS && calleesLength == 1) {
return 0;
}
else if (sourceToken != ETH_ADDRESS && calleesLength == 2) {
return 0;
}
if (_fee > 0) {
fee = receivedAmount.mul(_fee).div(10000);
}
return fee;
}
/**
* @dev Source take from GNOSIS MultiSigWallet
* @dev https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
*/
function externalCall(
address destination,
uint256 value,
uint256 dataOffset,
uint dataLength,
bytes memory data
)
private
returns (bool)
{
bool result = false;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
add(d, dataOffset),
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/**
* @dev Helper function to returns balance of a user for a token
* @param token Tokend address
* @param account Account whose balances has to be returned
*/
function tokenBalance(
address token,
address account
)
private
view
returns (uint256)
{
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
} | /**
* @dev The contract will allow swap of one token for another across multiple exchanges in one atomic transaction
* Kyber, Uniswap and Bancor are supported in phase-01
*/ | NatSpecMultiLine | refundGas | function refundGas(uint256 initialGas, uint256 mintPrice) private {
uint256 mintBase = 32254;
uint256 mintToken = 36543;
uint256 freeBase = 14154;
uint256 freeToken = 6870;
uint256 reimburse = 24000;
uint256 tokens = initialGas.sub(
gasleft()).add(freeBase).div(reimburse.mul(2).sub(freeToken)
);
uint256 mintCost = mintBase.add(tokens.mul(mintToken));
uint256 freeCost = freeBase.add(tokens.mul(freeToken));
uint256 maxreimburse = tokens.mul(reimburse);
uint256 efficiency = maxreimburse.mul(tx.gasprice).mul(100).div(
mintCost.mul(mintPrice).add(freeCost.mul(tx.gasprice))
);
if (efficiency > 100) {
freeGasTokens(tokens);
}
}
| /**
* @dev Helper method to refund gas using gas tokens
*/ | NatSpecMultiLine | v0.5.10+commit.5a6ea5b1 | BSD-3-Clause | bzzr://a414e7ebbd4e22e20905576e075c51708f507cc3b4782f370cdcb29302473dd4 | {
"func_code_index": [
14035,
14848
]
} | 8,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.